Automatically set the figure width depending on whether the layout is one or two column

I am wondering how do you usually deal with figure width when you are writing a paper. (use \linewidth, \textwidth ? others?)

Maybe we can just define a "switch" and use it with ifelse package?

(Assume that you are writing a onecolumn version, and you also want to know the twocolumn layout at the same time without adjusting the \witdh manually too often.)

EDIT. LaTeX is quite "intelligent" to format the text content. Can we let it deal with figures the same way?

That is, when we add a figure, we not only just set the width=..., but also add a tag for informing LaTeX that "I am setting this width according to A4 paper twocolumn".

Then when we change the layout to onecolumn, LaTeX knows how to handle (rescale).

EDIT

\usepackage{ifthen}
\newboolean{figColumnTrueOneFalseTwo}
\setboolean{figColumnTrueOneFalseTwo}{false}
%\setboolean{figColumnTrueOneFalseTwo}{true}

% in main.tex
\ifthenelse {\boolean{figColumnTrueOneFalseTwo}}{
% for onecolumn here
}{
% for twocolumn here
}

-
Is \columnwidth what you are looking for? –  karlkoeller Sep 2 '13 at 14:56
@karlkoeller Oh, I've never used \columnwidth, +1. Thanks! (I am looking for suggestions, and would like to know how people usually do! :)) –  Hongying Sep 2 '13 at 15:04
\columnwidth or \linewidth should do what you want. –  David Carlisle Sep 2 '13 at 15:09
–  egreg Sep 2 '13 at 15:27
Can you expalin the edit a bit better? Wasn't \includegraphics[width=\columnwidth]{...} enough? What do you need this info for? –  karlkoeller Sep 3 '13 at 8:23

As this question was solved in the comments, in order to remove from unanswered, this is a community wiki answer.

Sort answer: usually \includegraphics[width=\linewidth]{} automatically fit well in most cases.

Difference between \textwidth, \linewidth and \hsize (and \columnwidth) is well explained in the above link. In practice, in one column document, \textwidth,\columnwidth and \linewidth is the same length (while you are out of any special environment), so you can use any of these lengths to fix the width of the image:

\documentclass{article}
\begin {document}
\the\textwidth   % this length is 345.0pt
\the\linewidth   % this is  also  345.0pt
\the\columnwidth % this is again  345.0pt
\end{document}


However, if you change from one to two column, then \textwidth is more than twice the width of one column and largely inappropiate for the figures that must fit within one column:

\documentclass[twocolumn]{article}
\begin {document}
\the\textwidth   % this is now 469.0pt
\the\linewidth   % this is now 229.5pt
\the\columnwidth % this is now 229.5pt
\end{document}


So, one may think that, that as general rule, is safer \columnwidth, since this work in both formats. Nonetheless, in two columns documents are usual the figures extending in two columns (starred floats \begin{figure*} ...) where (one) \columnwidth is just the wrong option. Instead, \linewidth fill the space as expected in both starred and not starred floats, as well as in images without floats, in both one or two columns documents.

For images without floats and inside in some environment is not possible a general rule, but probably \linewidth is the choice in most cases. For example, in a itemize environment will be 20pt narrower that the column width, that probably is what you want for an "itemized" picture (...or may be not, it depend of what you want).

-