# How to dynamically add wider graphics to a two-column article?

I have a two-column article, which is still work in progress. In this article, I have to add figures once in a while, which tend to be a little wider than a single column, but two small to be span of the two.

I usually adjust the figures by moving them manually either to the left via \hspace*{-2cm} or (sometimes) to the right via \hspace*{2cm}, depending whether the figure is in the left or right column.

Since the article is still work in progress, I add sometimes text above the figures, which in turn might change their current position either from the right to the left column or vice versa. The figures, then, end up covering the text, compare example with mock figures below (please, note the comments within the code).

How can I tell LaTeX to automatically move the figures without me manually adjusting the figures to the left or right every time I add text above them?

\documentclass[a4paper]{article}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{float}
\begin{document}

\begin{multicols}{1}
\lipsum[1-3]
\begin{figure}[H]
\centering
\begin{tikzpicture} % this is how the mock figure does not suppose to be appear in the article
\hspace*{-2cm}\draw circle (2); % hspace here only simulates a wide graph or image (I was otherwise not able to add a picture here)
\end{tikzpicture}
\caption{Figure in two column}
\end{figure}
\lipsum[3-4]
\begin{figure}[H]
\centering
\begin{tikzpicture} % this is how the mock figure suppose to appear in the article
\hspace*{-2cm}\draw circle (2); % hspace only simulates a wide graph or image (see comment above)
\end{tikzpicture}
\caption{Figure in two column}
\end{figure}
\lipsum[5-6]
\end{multicols}
\end{document}


On this page, the mock figure appears in a not desired way:

On this page, the mock figure appears in the desired way:

If you read the documentation of multicol (e.g., by running texdoc multicol) you will see that since version 1.8 multicol supports \docolaction which offers precisely what you are looking for: different actions depending on the column you end up being in.

\documentclass[a4paper]{article}
\usepackage[colaction]{multicol}      % <--- add option
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{float}

\newcommand{\Wfigure}[2]
{\begin{figure}[H]
\docolaction                                            %<--- select what to do
{\makebox[\columnwidth][r]{#1}}
{\ERRORmiddle}                                 % fail in middlecolumn (lazy)
{\makebox[\columnwidth][l]{#1}}
\caption{#2}\end{figure}}

\begin{document}
\begin{multicols}{2}
\lipsum[1-3]
\Wfigure{%
\begin{tikzpicture}
\draw rectangle (8,2);
\end{tikzpicture}}
{Figure in some column}
\lipsum[3-4]
\Wfigure{%
\begin{tikzpicture}
\draw rectangle (8,2);
\end{tikzpicture}}
{Figure in some column}
\lipsum[5-6]
\end{multicols}
\end{document}


This will then need more than one LaTeX run (as it is internally using cross-referencing) but then you will get:

followed by

somewhat later on the second page.

• Wow! I completely missed that. Dec 14, 2016 at 18:27
• @PietvanOostrum :-) it does have its uses Dec 14, 2016 at 18:28