7

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

migrated from stackoverflow.com Apr 10 '13 at 0:59

This question came from our site for professional and enthusiast programmers.

6

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

  • It looks like that \if@twocolumn works in the opposite way – katang Dec 29 '14 at 20:29
1

Here is how I made a conditional to do different things with one or two columns:

\documentclass[onecolumn]{article}
\begin{document}

\makeatletter
\if@twocolumn
\newcommand{\whencolumns}[2]{
#2
}
\else
\newcommand{\whencolumns}[2]{
#1
}
\fi
\makeatother

\whencolumns{One Column}{Two Columns}
\end{document}

When this is defined, you can do the original question like:

\whencolumns{
 \includegraphics[width=0.5\linewidth]{FiguresSingle/figure.eps}
}{
 \includegraphics[width=0.7\linewidth]{FiguresDouble/figure.eps}
}

This method does assume that the entire document is one or two columns and isn't switching.

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.