LaTeX讲解系列(1):
如何优雅地插入图表
包括插入子图,多图排列,画模型图等等
具体代码以会议/期刊所给的模板格式为准
插入图片
插入一张图片
1 2 3 4 5 6 7 8 \begin {figure}[!htbp] \centering \includegraphics [width=0.4\textwidth ]{introduction_ 3_ cases.pdf} \caption {XXXXXX} \label {fig1:three_ cases} \end {figure}
插入多张图片
对于插入多张子图的组图,如果数量$$4的,建议在PPT或者draw.io
中手动排版一下,调整间距大小截图角度等组合成一个整体,作为单张图片来插入。
如果数量很多,比如\(5 \times
6\) 的阵列,可以使用
MulimgViewer
软件(https://github.com/nachifur/MulimgViewer)进行多图联排展现可视化,软件会自动合成一张大单图。
若使用LaTex的subfigure
来组图,实现方法如下:
但是困难是 1)一旦图片变多调试会变得非常麻烦 2)
非常容易overfull超过页面大小,除非把每张图片缩小的特别小,但这样就看不清了
3) 图片内部之间的白色间隔难以消除。非必要不用这种方式。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \begin {center}\begin {figure}[htbp] \centering \subfigure { \begin {minipage}[h]{0.4\linewidth } \centering \includegraphics [scale=0.45]{Fig/beat.png} \caption {Beating}\label {Beating} \end {minipage} \begin {minipage}[h]{0.6\linewidth } \centering \includegraphics [scale=0.45]{Fig/lean.png} \caption {leaning} \end {minipage} } \centering \subfigure { \begin {minipage}[h]{0.4\linewidth } \centering \includegraphics [scale=0.45]{Fig/catch_ up.png} \caption {Catch up} \end {minipage} \begin {minipage}[h]{0.6\linewidth } \centering \includegraphics [scale=0.45]{Fig/sneak.png} \caption {Sneaking} \end {minipage} } \subfigure { \begin {minipage}[h]{0.4\linewidth } \centering \includegraphics [scale=0.3]{Fig/stand.png} \caption {Stand still} \end {minipage} \begin {minipage}[h]{0.6\linewidth } \centering \includegraphics [scale=0.35]{Fig/slippery.png} \caption {Slippery} \end {minipage} } \centering \subfigure { \begin {minipage}[h]{0.4\linewidth } \centering \includegraphics [scale=0.3]{Fig/turnaround.png} \caption {Upside down} \end {minipage} \begin {minipage}[h]{0.6\linewidth } \centering \includegraphics [scale=0.3]{Fig/struggle.png} \caption {Struggle to turn around}\label {struggle} \end {minipage} }\end {figure}\end {center}
效果图:
插入表格
检查插入如下必要的宏包
1 2 \usepackage {graphicx}\usepackage {booktabs}
CS科研表格
效果图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \begin {table*}[htbp] \centering \resizebox {1.0\textwidth }{!}{ \begin {tabular}{l|cccc|ccc|ccc|c|c} \toprule Method & PPP & PPPP & QQ & QQQ & QQQQ & RRR & RRRR & TTTT & TTTTT & ZZZZZZ & mIoU & FPS \\ \hline Method-A & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & 100.0 & - \\ Method-B & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & 90.0 & - \\ Method-C & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & 85.0 & - \\ \bottomrule \end {tabular} }\caption {XXXXXX Performance.}\label {tab1:performance} \end {table*}
三线表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \begin {table}[htbp] \small \centering \resizebox {0.6\textwidth }{!}{ \begin {tabular}{ccccc} \toprule Method & PPP & PPPP & QQ & QQQ \\ \midrule Method-A & 100.0 & 100.0 & 100.0 & 100.0 \\ Method-B & 90.0 & 90.0 & 90.0 & 90.0 \\ Method-C & 85.0 & 85.0 & 85.0 & 85.0 \\ \bottomrule \end {tabular} }\caption {XXXXXX Performance.}\label {tab2:three_ line} \end {table}
补充:
Latex字号大小\tiny < \scriptsize < \footnotesize < \small < \normalsize < \large < Large < LARGE < huge < Huge
,
一般默认是\normalsize
。此外,在正文里若想只对一部分文字改变字号,可以{\Large Input your text here}
\resizebox{宽度}{高度}{}
和
\scalebox{0.65}
区别在于高度控制的不同。
“两者的区别在于高度的控制,前者控制相对高度,后者控制总高度,如果命令中的宽度或高度使用了感叹号代替,表示按照高度或宽度保持宽高比进行缩放”
列宽调整
将代码中的
\begin{tabular}{c|ccc}
中的每个c改成\begin{tabular}{ p{5pt} <<span class="hljs-cell">{\centering} | ccc}
,
其中花括号里面填写宽度数值,如果需要该列居中则加入
<<span class="hljs-cell">{\centering}
好像三线表中\toprule
,
\bottomrule
,如果要用竖线分割时会导致竖线在顶线和底线处断开。目前暂时没找到好的解决方法。如果均换成
\hline
,虽然竖线不会断开但是也没有粗细区别了。
多个子列合并
首先\usepackage{multirow}
下面两个博客讲解的都特别好,因此推荐看原文,就不再赘述。源代码中做了一些小改进,附文在下:
参考资料:
https://blog.csdn.net/liu16659/article/details/111656244
使用latex做三线表
E.g. 1
Table3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \begin {table}[!htbp] \centering \begin {tabular}{ccccccccccc} \toprule \multicolumn {3}{c}{\multirow {2}{*}{Method}}& \multicolumn {3}{c}{Homographic}& & \multicolumn {3}{c}{Hetergraphic}\\ \multicolumn {3}{c}{} & Precision & Recall & F1 & & Precision & Recall & F1\\ \hline \multicolumn {3}{c}{A}& 50 & 0 & 100& & 200 & 300 & 300\\ \multicolumn {3}{c}{B}& 100 & 100 & 0 & & 100 & 200 & 200\\ \multicolumn {3}{c}{C}& 150 & 200 & 100 & & 0 & 100 & 200\\ \bottomrule \end {tabular} \caption {hihihi}\end {table}
补充:
注意用到multirow
和multicol命令时需要使用宏包\usepackage{multirow}
源博客代码中&Recall & F1&\\
这里多了一个&
,这里去掉了多余的&
修复bug
E.g. 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 \begin {tabular}{ @{}l c@{\hspace {0.5em}} c@{\hspace {0.5em}} c@{}p{1.0em}@{} c@{\hspace {0.5em}} c@{\hspace {0.5em}}c @{}p{1.0em}@{} c@{\hspace {0.5em}} c@{\hspace {0.5em}}c @{}p{1.0em}@{} c@{} }\toprule \multirow {2}{*}{Method} & \multicolumn {3}{c}{A} & & \multicolumn {3}{c}{\PrivateDatasetOne {}} & & \multicolumn {3}{c}{\PrivateDatasetTwo {}} & & \multirow {2}{*}{Avg Rank}\\ & R1↓ & R2↓ & R3↑ & & R1↓ & R2↓ & R3↑ & & R1↓ & R2↓ & R3↑\\ \midrule Method1~\cite {foo_ 1} & 1.910 & 10.2 & 89.5 & & & & & & & & & & \\ Method2 ~\cite {foo_ 2} & 1.724 & 9.3 & 91.0 & & & & & & & & & & \\ \midrule Ours & 1.772 & 8.7 & 91.4 & & & & & & & & \textbf {1.4} & & \\ \bottomrule \end {tabular}\begin {table*}[t!] \centering \caption { \textbf {Main Performance} of \method {} with 123 } \resizebox {0.9\linewidth }{!}{ \input {tbl/tb1_ main_ table} \label {table:main_ perform} } \\ \begin {minipage}{\linewidth } \scriptsize \vspace {0.4em} \begin {itemize} \item [$ ^ \dagger $ ] Most baselines are sourced from Fooo_ 0~\cite {Foo_ 0}, except for the A benchmark. \end {itemize} \end {minipage}\end {table*}
补充:
值得学习的地方:①
把table
环境和tabular
环境分开,分到两个文件方便层次化的管理,避免一个文件内内容太杂。②可以在表格末尾插入minipage
,
放一些想要添加的描述说明;表格标题放在tabular
的上面。 ③
通过增加额外的空白列实现一定的分隔效果。④
使用\makecell{}
命令,当单元格内容较长时在该环境里可以实现更轻松的直接换行,不需要外部重新计算multirow
或multicolumn
拆分为多少个。
E.g. 3
https://blog.csdn.net/qq_34823530/article/details/112504329
Latex复杂三线图的处理
Table4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 \begin {table*} \centering \resizebox {1.0\textwidth }{!}{ \begin {tabular}{ccccccc} \toprule \multirow {2}{*}{\textbf {Model}} & \multirow {2}{*}{\textbf {Skipped}} & \multirow {2}{*}{\textbf {Dilated}} & \multirow {2}{*}{\textbf {Attention}}& \multirow {2}{*}{\textbf {Fine-Tune}} & \multicolumn {2}{c}{\textbf {Accuracy}} \\ & & & & & 5-way 1-shot & 5-way 5-shot \\ \midrule \textbf {Relation Net }& \checkmark & & & & 0.8449 & 0.8325 \\ \textbf {Relation Net} & \checkmark & & & \checkmark & 0.8950& 0.8488 \\ \textbf {Relation Net} & \checkmark & \checkmark & & & 0.8624& 0.8450 \\ \textbf {Relation Net} & \checkmark & \checkmark & & \checkmark & 0.8866& 0.8647 \\ \textbf {Relation Net} & \checkmark & & \checkmark & & 0.8532& 0.8599 \\ \textbf {Relation Net} & \checkmark & & \checkmark & \checkmark & 0.9268& 0.8925 \\ \cline {1-7} \textbf {Our model} & \checkmark & \checkmark & \checkmark & & 0.8990& 0.8537 \\ \textbf {Our model} & \checkmark & \checkmark & \checkmark & \checkmark & \textbf {0.9486}& \textbf {0.9039} \\ \bottomrule \end {tabular} } \label {tbl:table1} \caption {Comparison of different obfuscations in terms of their transformation capabilities}\end {table*}
补充:
1.为了好看方便对齐,在源代码基础上增加了\resize{}{}{}
控制命令。
\cline{}
命令和\hline
命令不同之处:
The command produces a horizontal line extending across the entire
table. It can only be issued after a line break \. The command draws a
horizontal line from the left side of column n to the right side of
column m. It may only be issued after a line break, and several can be
issued at
once.
注意图表中使用的对号\checkmark
命令需要引用\usepackage{amssymb}
宏包。此外对号也有不同的风格
checkmart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \documentclass {article}\usepackage {bbding}\usepackage {pifont}\usepackage {wasysym}\usepackage {amssymb}\begin {document}\checkmark \Checkmark \CheckmarkBold \ding {51}\ding {52}\CheckedBox \end {document}
参考资料