我有一个 LaTeX 文档,它生成两列文本。当我插入浮动环境时,两列之间的顶线没有对齐。我的问题是如何对齐它们。非常感谢。
\documentclass[twocolumn]{elsarticle}
\usepackage{algorithmic}
\usepackage{lipsum}
\begin{document}
\lipsum
\begin{figure}
\noindent\fbox{%
\parbox{.97\linewidth}{%
\begin{algorithmic}[1]
\REQUIRE RGB color space RGB[p]
\ENSURE CIELab color space LAB[p]
\STATE \_\_global\_\_ void
\STATE kernel\_rgb2lab(RGB,\ LAB)\{
\STATE \ \ this kernel is executed creating one thread for each pixel in parallel.
\STATE \ \ \textbf{int} x = threadIdx.x+blockIdx.x $\times$ blockDim.x;
\STATE \ \ \textbf{int} y = threadIdx.y+blockIdx.y $\times$ blockDim.y;
\STATE \ \ LAB[x,y] = rgb2lab(RGB[x,y]);
\STATE \}
\end{algorithmic}%
}}
\caption{algorithm}
\end{figure}
\lipsum
\end{document}
结果:
很明显,右栏有一个小边距。你能告诉我如何去掉它吗?
答案1
您只需使用 插入适当的垂直调整即可\vspace
。
在您的情况下,由于您已将整个算法放在里面\fbox
,因此我们插入\fboxsep
+ \fboxrule
:
\documentclass[twocolumn]{elsarticle}
\usepackage{algorithmic}
\usepackage{lipsum}
\begin{document}
\lipsum
\begin{figure}
\vspace*{\dimexpr\fboxsep+\fboxrule}
\fbox{%
\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\raggedright
\begin{algorithmic}[1]
\REQUIRE RGB color space RGB[p]
\ENSURE CIELab color space LAB[p]
\STATE \_\_global\_\_ void
\STATE kernel\_rgb2lab(RGB,\ LAB)\{
\STATE \ \ this kernel is executed creating one thread for each pixel in parallel.
\STATE \ \ \textbf{int} x = threadIdx.x + blockIdx.x $\times$ blockDim.x;
\STATE \ \ \textbf{int} y = threadIdx.y + blockIdx.y $\times$ blockDim.y;
\STATE \ \ LAB[x,y] = rgb2lab(RGB[x,y]);
\STATE \}
\end{algorithmic}%
}}
\caption{algorithm}
\end{figure}
\lipsum
\end{document}
注意宽度的选择以\parbox
使其适合列宽(\linewidth
)。