9

How can I position a figure (picture) so that it:

  • is aligned on the left-hand side with the text (this is in two column page)
  • touches (or exceeds) the right-hand side of the page?

An example can be found here: http://library.fes.de/pdf-files/akademie/berlin/04801.pdf (go to any page with a picture and see how the picture is placed.) Note: The example is not what I would call pretty; I think the design is hideous. None the less, I'd like to know how to accomplish this style design for pictures.

4

1 Answer 1

5
\documentclass[a4paper,twocolumn]{article}
\usepackage{lipsum,graphicx}
\newcommand{\mydimright}{%
  \dimexpr\paperwidth-1in-\hoffset-\oddsidemargin-
  \columnwidth-\columnsep\relax}
\newcommand{\mydimleft}{%
  \dimexpr1in+\hoffset+\oddsidemargin+\columnwidth\relax}

\begin{document}
\lipsum[1]
\begin{flushleft}
\makebox[\columnwidth][r]{%
\includegraphics[height=1cm,width=\mydimleft]{try}}
\end{flushleft}
\lipsum[1-5]
\begin{flushleft}
\makebox[\columnwidth][l]{%
\includegraphics[height=1cm,width=\mydimright]{try}}
\end{flushleft}
\end{document}

There is no immediate access to the right margin width, which has to be computed in an indirect way.

With the command \layout of the layout package, one can look at the relevant lengths. I've put also \hoffset, because some classes might change it.

Here try is the graphic file I always use for tests. I've used flushleft just in order to avoid LaTeX trying to be smart with figure placement.

-- Extended version for automatic placement in the figure environment --

Here it is, following Martin's suggestion; the command \touchmarginincludegraphics works like its sibling \includegraphics except, of course, that the keyword width should not be specified.

\documentclass[a4paper,twocolumn]{article}
\usepackage{lipsum,graphicx}

\makeatletter
\def\tmig@r{\dimexpr\paperwidth-1in-\hoffset-
  \oddsidemargin-\columnwidth-\columnsep\relax}
\def\tmig@l{\dimexpr1in+\hoffset+\oddsidemargin+\columnwidth\relax}
\newcommand{\touchmarginincludegraphics}[2][]{%
  \begingroup
  \if@firstcolumn
    \def\tmig@place{r}%
  \else
    \def\tmig@place{l}%
  \fi
  \makebox[\columnwidth][\tmig@place]{%
    \includegraphics[#1,width=\@nameuse{tmig@\tmig@place}]{#2}}
  \endgroup}
\makeatother

\begin{document}
\lipsum[1]

\begin{figure}[!h]
\touchmarginincludegraphics[height=1cm]{try}
\end{figure}

\lipsum[1-4]

\begin{figure}[!h]
\touchmarginincludegraphics[height=1cm]{try}
\end{figure}

\lipsum[2]
\end{document}
4
  • The images in the linked PDF look like floats to me. You might want to update your code to insert \begin{figure}[t] and use \if@firstcolumn to select the direction. May 13, 2011 at 16:27
  • @Martin: I've added the code, thanks for suggesting \if@firstcolumn.
    – egreg
    May 13, 2011 at 17:05
  • Thank you, that works! I removed the height=1cm option, that makes the aspect ratio stay.
    – Unapiedra
    May 14, 2011 at 15:09
  • @Unapiedra: Yes, the height=1cm was there just to make a one page example with figures in both columns.
    – egreg
    May 14, 2011 at 16:56

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.