4

I have a LaTeX document below which generates two column text. When I insert a float environment, the top line between two column is not aligned. My question is how to align them. Thanks a lot.

\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}

Results:

enter image description here

Obviously, there is a small margin in the right column. Could you tell me how to remove it?

2

You can just insert an appropriate vertical adjustment using \vspace.

In your case, since you've placed the entire algorithm inside an \fbox, we insert \fboxsep+\fboxrule:

enter image description here

\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}

Note the choice of width for \parbox to make it fit within the column width (\linewidth).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.