# How to align text and floats on the top of text line in a two column environment

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:

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

## 1 Answer

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:

\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).