[Tex/LaTex] If two columns LaTeX

conditionalstwo-column

I am writing a paper in LaTeX. I will need both the one-column and two-column versions of the paper. For this, the figure sizes/configurations need to be different in the two documents. I am looking for a command like \iftwocolumn! Do you know if it exists and if not how can I define and use it?

I would need something like:

\begin{figure}[tb]
\iftwocolumn\includegraphics[width=0.7\linewidth]{FiguresDouble/figure.eps}
\else\includegraphics[width=0.5\linewidth]{FiguresSingle/figure.eps}
\fi

Best Answer

\linewidth or \columnwidth should work, since a non-twocolumn document technically consists of a single column (of width \columnwidth).

However, if you're using the traditional twocolumn mode of (say) article, the condition \if@twocolumn is available for testing/branching.

Here's a short example showing the difference:

\documentclass{article}
\usepackage{graphicx,showframe}% http://ctan.org/pkg/{graphicx,showframe}
\begin{document}
\noindent
\makeatletter%
\if@twocolumn%
  \includegraphics[width=\columnwidth]{example-image-a}%
\else% \@twocolumnfalse
  \includegraphics[width=\columnwidth]{example-image-b}%
\fi
\makeatother
\end{document}

Note that you require the use of a \makeatletter...\makeatother pair, since the command definition of the conditional contains @. See What do \makeatletter and \makeatother do?

Related Question