LaTeX中使用图例
绘图
pgfplots
TikZ
配图
配图在页面中的位置
[htbp],越靠前优先级越高:- b(Bottom):当前页的底部
- h(Here):Place the table at the spot where the table environment appears in the text
- p(Page):放置在下一页顶部
- t(Top):当前页的顶端
裁切配图
- 使用
trim参数,trim的四个参数分别为左、下、右、上。变量可以采用{.5\width}或1cm等形式,clip为执行裁切\includegraphics[width=0.15\linewidth, trim={0 0 200pt 0},clip]{figures/test.png}
给图标手动添加横坐标
- 参考代码
\begin{figure}[t]{
\centering
\begin{tikzpicture}
% 插入图片
\node[anchor=south west, inner sep=0] (img)
{\includegraphics[width=0.8\linewidth]{exp_count_bar.jpg}};
\begin{scope}[
x={(img.south east)},
y={(img.north west)}
]
\foreach \i in {1,...,11} {
\node[anchor=north] at ({0.13+(\i-1)*0.08}, 0.08)
{\tiny $S_{\i}$};
}
\end{scope}
\end{tikzpicture}
\caption{Your caption here.}
\label{fig:exp_count}
}\end{figure}配图的排版
多个子图
使用subcaption包(个人不推荐)
- 存在的问题:
- 会改写图例的格式
- 如果图例长度不一致,需要手动对齐
\begin{figure} \centering \begin{subfigure}[b]{0.235\textwidth} \centering \includegraphics[width=\textwidth]{figures/find_rod/0_full_cloud.jpg} \caption{The workspace is captured by the RGB-D camera to generate colorized point cloud.} \label{fig:raw_pcd} \end{subfigure} \hfill \begin{subfigure}[b]{0.235\textwidth} \centering \includegraphics[width=\textwidth]{figures/find_rod/2_dbscan.jpg} \caption{The robot and the background are subtracted. The data points are clustered by distance.} \label{fig:dbscan} \end{subfigure} \caption{Key steps to estimate the rod's dimension and pose.} \label{fig:find_rod} \end{figure}
使用subfigure包
- 待补充
使用subfig包(subfloat,IEEEtrans推荐)
- 引用包
\usepackage[caption=false, font=footnotesize]{subfig} - 基本格式为
\subfloat[Your sub-caption \label{fig:1}]{图片} - 默认图例与图片等宽,修改图例宽度的示例如下(添加
\makebox[0.95\linewidth]拓宽图像)
\begin{figure}
\centering
\subfloat[aaa. \label{fig:aaa}]
{\includegraphics[width=.45\linewidth]{figures/1.png} }
\hfill
\subfloat[bbb. \label{fig:bbb}]
{\includegraphics[width=.45\linewidth]{figures/2.png} }
\subfloat[ccc. \label{fig:ccc}]
{\makebox[0.95\linewidth]{\includegraphics[width=.45\linewidth]{figures/3.png} }}
\caption{ddd.}
\label{fig:ddd}
\end{figure}- 若存在子图,但是子图仅用来拼接,不需要子图的图例
- 先取消子图图例
\captionsetup[subfloat]{labelformat=empty} - 再向上收缩一行
\vspace{-1\baselineskip} \subfloat后的[]不能省略,即使不准备添加label
- 先取消子图图例
\begin{figure}[htb]
\captionsetup[subfloat]{labelformat=empty}
\centering
\subfloat[]
{\includegraphics[width=0.30\linewidth]{figures/discussion/0_init.jpg}}
\hfill
\subfloat[]
{\includegraphics[width=0.3\linewidth]{figures/discussion/1_lift.jpg} }
\hfill
\subfloat[]
{\includegraphics[width=0.3\linewidth]{figures/discussion/2_place_w_shift.jpg} }
\vspace{-1\baselineskip}
\caption{The fixed end of the Rope3 is shifted during creating the first wrap because of its' stiffness. The red arrows are used as references.}
\label{fig:first_wrap_pushing}
\end{figure}使用subfig包时对子图进行调整
只用子图进行拼图,隐藏子图图题
- 使用
\captionsetup[subfloat]{labelformat=empty},可以用\vspace{-1\baselineskip}消除多余空行
\begin{figure}[t]
\captionsetup[subfloat]{labelformat=empty}
\centering
\quad
\subfloat[]
{\includegraphics[height=80px]{1.jpg} }
\label{fig:1}
\hfill
\subfloat[]
{\includegraphics[height=80px]{2.jpg} }
\label{fig:2}
\hfill
\subfloat[]
{\includegraphics[height=80px]{3.jpg} }
\label{fig:3}
\quad
\vspace{-1\baselineskip}
\caption{Caption.}
\label{fig:label}
\end{figure}会议/期刊模板要求子图无图题,但是想将注脚写在图片下方
- 使用
\parbox放置图片和文字,\footnotesize或其它选项调整字体大小,通过[*pt]调整文字到图片的间距、文字行间距(直接跟在换行符后)以及文字到子图序号的间距
\begin{figure*}[t]{
\def\imgscale{0.24}
\centering
\subfloat[]{
\parbox[t]{\imgscale\linewidth}{
\centering\includegraphics[width=\linewidth]{1.jpg}\\[2pt]
{\footnotesize \(\begin{aligned}\text{Initial state } S_{1}\\\text{ }\end{aligned}\)}\\[-4pt] }
\label{fig:1.1}}
\hfill
\subfloat[]{
\parbox[t]{\imgscale\linewidth}{
\centering\includegraphics[width=\linewidth]{2.jpg}\\[2pt]
{\footnotesize \(\begin{aligned}S^{3D}_{2}&=\lbrack a, b, c\rbrack\\&=\lbrack 1,0,0\rbrack\end{aligned}\)}\\[-4pt] }
\label{fig:1.2}}
\hfill
\subfloat[]{
\parbox[t]{\imgscale\linewidth}{
\centering\includegraphics[width=\linewidth]{3.jpg}\\[2pt]
{\footnotesize text line 1\\[-3pt] test line 2}\\[-4pt] }
\label{fig:1.3}}
\caption{Text.}
\label{fig:1}
}\end{figure*}图片位置
- 通过
\raisebox调整图片高度
\begin{figure}[t]
\centering
\subfloat[\label{fig:1}]{\raisebox{10px}
{\includegraphics[height=40px]{figures/1.jpg} }}
\quad
\subfloat[ \label{fig:2}]
{\includegraphics[height=60px]{figures/1.jpg} }
\caption{Example.}
\label{fig:examples}
\end{figure}通过声明变量统一缩放比例
- 注意需要大括号避免变量全局化,使用
\def
\begin{figure}[t]{
\def\imgscale{0.28}
\captionsetup[subfloat]{labelformat=empty}
\centering
\subfloat[a) \label{fig:a}]
{\includegraphics[width=\imgscale\linewidth]{figures/a.jpg} }
\caption{Your text here.}
\label{fig:the_figure}
}\end{figure}图例比图片宽
- 使用
\makebox
\begin{figure}[ht]
\centering
%\qquad
\subfloat[Subcaption 1.\label{fig:1}]{\makebox[5.5cm][c]
{\includegraphics[height=0.18\textheight]{figures/1.jpg}}}
\qquad
\subfloat[Subcaption 2.\label{fig:2}]
{\includegraphics[height=0.18\textheight]{figures/2.png}}
\hfill
\caption{Caption.}
\label{fig:3}
\end{figure}- 使用
\minipage
\begin{figure}[ht]
\centering
%\qquad
\subfloat[Subcaption 1.\label{fig:1}]
{\begin{minipage}[t]{0.33\linewidth}
\centering\includegraphics[height=0.18\textheight]{figures/1.jpg}
\end{minipage}}
\qquad
\subfloat[Subcaption 2.\label{fig:2}]
{\includegraphics[height=0.18\textheight]{figures/2.png}}
\hfill
\caption{Caption.}
\label{fig:3}
\end{figure}非对称布局(如左一右二)
\begin{figure}
\begin{minipage}{.25\textwidth}
\begin{subfigure}{\linewidth}
\centering
\includegraphics[width=.95\linewidth]{figures/1.jpg}
\caption{Caption a.}
\label{fig:a}
\end{subfigure}
\end{minipage}
\hspace{.005\textwidth}
\begin{minipage}{.22\textwidth}
\begin{subfigure}{\linewidth}
\centering
\includegraphics[width=.95\linewidth]{figures/2.jpg}
\caption{Caption b.}
\label{fig:b}
\end{subfigure}
\begin{subfigure}{\linewidth}
\centering
\includegraphics[width=.95\linewidth]{figures/3.jpg}
\caption{Caption c.}
\label{fig:c}
\end{subfigure}
\end{minipage}
\caption{Estimate the rope's width and color}
\label{fig:rope_width}
\end{figure}横跨双列(也适用于表格)
\begin{figure*}[ht]
\end{figure*}-
注意因为Latex编译系统的问题,跨双列的图片/表格总会被放置到下一页,解决方案是将其代码的位置往前移动。
Double column floats always go on the next page at the earliest (they can’t be placed on the current page as the first column may already have been set full height, so in a real document you just need to move the
figure*environment earlier in the source, so that it is seen before the text that ends on that page. In the rare cases that you want the float at the top of the first page, you don’t want a float at all and you can simply use -
默认位置配置只有t(下页顶端)和p(文档末尾)可选,b(下页底端)和h(当前位置)不可用
-
强制使用b的方法(引用
dblfloatfix包,Instead, use Morten Hogholm’a dblfloatfix which combines the features of both fixltx2e and stfloats:):
\usepackage{dblfloatfix}
\begin{figure*}[!b]
\end{figure*}
- 未测试
\twocolumn[{\includegraphics{...}}]在标题上或标题下横跨双列
- 使用
\AddToHook,区别在于是cmd/@maketitle/before或cmd/@maketitle/after,参考floats - Setting figure that spans over two columns, on top of the first page, below the title - TeX - LaTeX Stack Exchange - 宽图片在标题上方
\begin{document}
\AddToHook{cmd/@maketitle/before}{%
\begin{minipage}{\textwidth}
\bigskip
\includegraphics[height=4cm]{notch_detection.png}\dotfill
\includegraphics[height=4cm]{slicing.png}
\end{minipage}%
\par
\bigskip
}
\maketitle
\thispagestyle{empty}
\pagestyle{empty}- 宽图片在标题下方
\begin{document}
\AddToHook{cmd/@maketitle/after}{%
\begin{minipage}{\textwidth}
\bigskip
\includegraphics[height=4cm]{1.png}\dotfill
\includegraphics[height=4cm]{2.png}
\end{minipage}%
\par
\bigskip
}
\maketitle
\thispagestyle{empty}
\pagestyle{empty}绘图
- 绘图插件 Sketch
- 操作
sketch -o scene_sk.tex scene.skpdflatex -shell-escape scene.tex - Latex Sketch Plugin
- latexdraw
- 绘图插件的插件Sketch-lib
- 操作