记录一些 Latex 的技巧

时间:2023-01-18 06:42:31

Latex 一些技巧:

1. 如何创建不浮动的的 figure 和 table

\makeatletter
\newcommand{\figcaption}{\def\@captype{figure}\caption}
\newcommand{\tabcaption}{\def\@captype{table}\caption}
\makeatother

\begin{center}
\includegraphics[width=0.8\textwidth]{exp2/mpi_time_size.eps}\\
\figcaption{MPI 实现高斯消元计算行列式的程序运行时间与矩阵大小变化关系}\label{fig:mpi2}
\end{center}

\begin{center}
\begin{tabular}{c|cccccc}
\toprule
进程数 & 1 & 2 & 4 & 8 & 16 & 32 \\ \hline
1000 阶 & 0.711 & 0.452 & 0.331 & 0.239 & 0.226 & 2.380 \\
1200 阶 & 1.633 & 1.074 & 0.609 & 0.354 & 0.311 & 3.261 \\
1400 阶 & 2.905 & 1.912 & 1.204 & 0.448 & 0.386 & 2.623 \\
\bottomrule
\end{tabular}
\tabcaption{MPI 实现高斯消元计算行列式不同进程数下的运行时间(单位:s)}\label{tab:mpi}
\end{center}

2. 如何让表格填满
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}c|ccccc|ccccc}
其中 @{\extracolsep{\fill}} 就是用来干这个的.

3. 两个图并排插入一行:

\begin{figure}[htbp]
\centering
\begin{minipage}{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{文件名}
\caption{标题}\label{fig:f1}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{文件名}
\caption{标题}\label{fig:f2}
\end{minipage}\vspace{\baselineskip}
\end{figure}

4. 子图的插入方法

\usepackage{graphicx}和\usepackage{subfigure}
\begin{figure}[htbp]
\centering
\subfigure[第1个子图标题]{
\label{第1个子图标签(通常为fig:subfig1:subsubfig1)}
\includegraphics[width=0.4\textwidth]{文件名}}
\subfigure[第2个子图标题]{
\label{第2个子图标签(通常为fig:subfig1:subsubfig2)}
\includegraphics[width=0.4\textwidth]{文件名}}
\caption{总标题}\label{总标签(通常为fig:subfig1)}
\vspace{\baselineskip}
\end{figure}

5. \graphicspath{{Figures/}} 指定图片路径

6. 公式环境中(比如 equation, align 等)不能有空行,
否则会提示 paragraph ended before *** was complete...

7. 双栏排版,

  \begin{multicols}{2}

    \newpage % 切换到另一栏,否则默认底端对齐

  \end{multicols}

 用 \begin{colums}[T] 更灵活:

\begin{columns}[T]
    \begin{column}{0.4\linewidth}
    
    \end{column}
    
    \begin{column}{0.6\linewidth}
  
    \end{column}
\end{columns}

还可以嵌套使用哦! 

8. \newcommand{\argmax}{\operatornamewithlimits{argmax}}

     记录一些 Latex 的技巧

 9. 插入代码:

 1 \usepackage{xcolor}
 2 \usepackage{listings}
 3 
 4 \ifdefined \lstavoidwhitepre
 5 \lstavoidwhitepre
 6 \lstdefinestyle{colors}{keywordstyle={\bf\color{blue}}, commentstyle={\color{dkgreen}}, stringstyle=\color{mauve}}
 7 \lstset{language=C, style=colors, backgroundcolor=\color{lightblue}}
 8 \else
 9 \lstdefinestyle{colors}{keywordstyle={\bf\color{blue}}, commentstyle={\color{dkgreen}}, stringstyle=\color{mauve}}
10 \lstset{language=C, style=colors,basicstyle=\footnotesize, backgroundcolor=\color{lightblue}, showspaces=false, showstringspaces=false, showtabs=false, frame=single, breaklines=true, basewidth=5.5pt }
11 \fi
12 
13 ....
14 \begin{document}
15     \lstinputlisting{hello.c}
16 \end{document}

排版效果如下图:

记录一些 Latex 的技巧

 

记录一些 Latex 的技巧

9. 表格中插入多行 \parbox

\parbox

\parbox[position][height][inner-pos]{width}{text}

parbox is a box whose contents are created in paragraph mode. The \parbox has two mandatory arguments:

  • width - specifies the width of the parbox, and
  • text - the text that goes inside the parbox.

LaTeX will position a parbox so its centre lines up with the centre of the text line. The optional position argument allows you to line up either the top or bottom line in the parbox (default is top).

If the height argument is not given, the box will have the natural height of the text.

The inner-pos argument controls the placement of the text inside the box. If it is not specified, position is used.

  • t --- text is placed at the top of the box.
  • c --- text is centred in the box.
  • b --- text is placed at the bottom of the box.
  • s --- stretch vertically. The text must contain vertically stretchable space for this to work.

详见:http://herbert.the-little-red-haired-girl.org/html/latex2e/$5cparbox.html

 

待续。。