2列のLaTeXの場合

2列のLaTeXの場合

私はLaTeXで論文を書いています。1列版と2列版の両方の論文が必要です。このため、図のサイズや構成は2つの文書で異なる必要があります。次のようなコマンドを探しています。\iftwocolumnこれが存在するかどうか、存在しない場合はどのように定義して使用できるかご存じですか?

次のようなものが必要です:

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

答え1

\linewidthまたは\columnwidth、非文書twocolumnは技術的には1つの列(幅\columnwidth) で構成されるためです。

しかし、従来のtwocolumnのモード(例えば)を使用している場合はarticle、条件\if@twocolumnテスト/分岐に使用できます。

違いを示す短い例を以下に示します。

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

\makeatletter...の使用が必要であることに注意してください。\makeatother条件文のコマンド定義に が含まれているため、@何をす\makeatletterべき\makeatotherか?

答え2

1 列または 2 列でさまざまなことを実行する条件を作成した方法を次に示します。

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

これが定義されると、元の質問を次のように実行できます。

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

この方法では、ドキュメント全体が 1 列または 2 列であり、切り替えが行われないことを前提としています。

関連情報