LaTeX 图片位置参数:
- h (here): 尽量将图像放置在当前位置。
- t (top): 将图像放置在页面的顶部。
- b (bottom): 将图像放置在页面的底部。
- p (page of floats): 将图像放置在专门的浮动页面上,即一个只包含图像或表格的页面。
- !: 忽略某些限制,允许 LaTeX 更加灵活地安排图像位置。
- H (from the
float
package): 强制图像放置在当前位置,禁用浮动。
这些参数可以组合使用,例如:
htbp
: 尝试在当前位置放置图像,如果不能就将其放置在页面顶部、底部,或者单独的一页浮动页面上。!ht
: 忽略一些限制,更加灵活地将图像放置在当前页面的位置。
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{example-image} % 这里插入图像文件路径
\caption{示例图像} % 图像标题
\label{fig:example} % 图像标签,方便引用
\end{figure}
\end{document}
插入横跨两栏的图片:
\documentclass[twocolumn]{article} % 双栏文档
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
\begin{figure*}[htbp]
\centering
\includegraphics[width=\textwidth]{example-image} % 这里插入图像文件路径
\caption{横跨两栏的示例图像} % 图像标题
\label{fig:wide-example} % 图像标签,方便引用
\end{figure*}
\end{document}
控制大小,位置,旋转
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
% 设置图像的宽度为页面宽度的50%
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{example-image}
\caption{设置图像宽度}
\label{fig:width-example}
\end{figure}
% 设置图像的高度为3cm
\begin{figure}[htbp]
\centering
\includegraphics[height=3cm]{example-image}
\caption{设置图像高度}
\label{fig:height-example}
\end{figure}
% 按比例缩放图像为原始大小的70%
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.7]{example-image}
\caption{按比例缩放图像}
\label{fig:scale-example}
\end{figure}
% 将图像旋转45度
\begin{figure}[htbp]
\centering
\includegraphics[angle=45, width=0.5\textwidth]{example-image}
\caption{旋转图像}
\label{fig:angle-example}
\end{figure}
\end{document}
设置图像边距
使用 \includegraphics
命令时,你可以设置图像的边距或裁剪区域。例如,使用 trim
和 clip
选项来裁剪图像。
trim=l b r t
:分别从图像的左、下、右、上裁剪。
clip
:激活裁剪。
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
\begin{figure}[htbp]
\centering
% 从图像左边裁剪2cm,底部裁剪1cm,右边裁剪3cm,上边裁剪4cm
\includegraphics[trim=2cm 1cm 3cm 4cm, clip, width=0.6\textwidth]{example-image}
\caption{裁剪图像}
\label{fig:trim-example}
\end{figure}
\end{document}
图像和文本对齐
使用 \centering
让图像居中显示。你也可以使用 \raggedright
或 \raggedleft
来控制图像的左对齐或右对齐。
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
% 图像居中
\begin{figure}[htbp]
\centering
\includegraphics[width=0.6\textwidth]{example-image}
\caption{居中的图像}
\label{fig:center-example}
\end{figure}
% 图像左对齐
\begin{figure}[htbp]
\raggedright
\includegraphics[width=0.6\textwidth]{example-image}
\caption{左对齐的图像}
\label{fig:left-example}
\end{figure}
% 图像右对齐
\begin{figure}[htbp]
\raggedleft
\includegraphics[width=0.6\textwidth]{example-image}
\caption{右对齐的图像}
\label{fig:right-example}
\end{figure}
\end{document}
加边框
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\usepackage{fancybox} % 引入fancybox包来创建边框
\begin{document}
% 使用fancybox包添加边框
\begin{figure}[htbp]
\centering
\fbox{\includegraphics[width=0.6\textwidth]{example-image}} % 图像加上边框
\caption{有边框的图像}
\label{fig:frame-example}
\end{figure}
\end{document}
**图像引用
\documentclass{article}
\usepackage{graphicx} % 引入graphicx包以插入图像
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{example-image}
\caption{图像示例}
\label{fig:example}
\end{figure}
在文中引用图像:图像~\ref{fig:example} 展示了一个示例。
\end{document}