1

I want to resize a marginfigure in twoside margin

Here is my MWE

\documentclass{caesar_book} 
% -- use dummy graphics
\usepackage{mwe} 
%auto generate the bib file
\usepackage{filecontents} 
% -- language: English -- 
\usepackage[english]{babel}
% -- biblatex --
\usepackage[backend=biber,style=philosophy-classic]{biblatex} % xxx
% the .bib file with the references
\usepackage{blindtext}
\begin{document}
\section*{Scaling a marginfigure in the direction of a marginside}
\blindtext[1]
\begin{marginfigure}%
    \includegraphics[width=1.2\textwidth]{example-image-a}%
    \caption{A small rectangle put in the margin.\label{rectangle}}%
\end{marginfigure}%
\blindtext[2]
\newpage
\blindtext[1]
\begin{marginfigure}%
    \includegraphics[width=1.2\textwidth]{example-image-a}%
    \caption{A small rectangle put in the margin.\label{rectangle}}%
\end{marginfigure}%
\blindtext[2]
\end{document}

The problem appears when the marginfigure is on the left margin.

enter image description here

Resizing a figure on the left margin results a figure and a text overlap.

  • 1
    Have you tried width=\textwidth? If you choose something larger it is not too surprising that something would overlap with other bits of the page eventually. – moewe Jun 10 at 6:38
  • 2
    If you really need to have figures larger than the \textwidth you could use \hspace*{-0.2\textwidth}\includegraphics[width=1.2\textwidth]{example-image-a} for the second figure. – user121799 Jun 10 at 6:40
  • @marmot: Yes! That solves my problem. Gracias! – marya Jun 10 at 6:56
2

Use the \mfincludegraphics command for inserting oversized pictures; the excess will be automatically moved in the direction of the outer margin. You don't need to know what page the picture will be typeset on.

This may require multiple runs of LaTeX to stabilize.

In the code below I added two blank pages so one figure falls in a left-hand page and one in a right-hand page, to see the difference.

\documentclass{caesar_book} 

\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{refcount}

\usepackage{blindtext}

\newcounter{mfig}
\newcommand{\mfincludegraphics}[2][]{%
  \refstepcounter{mfig}\label{\themfig}%
  \makebox[\textwidth][\ifodd\getpagerefnumber{\themfig}l\else r\fi]{%
    \includegraphics[#1]{#2}%
  }%
}


\begin{document}

\mbox{}\newpage

\section*{Scaling a marginfigure in the direction of a marginside}
\blindtext[1]

\begin{marginfigure}
    \mfincludegraphics[width=1.2\textwidth]{example-image-a}
    \caption{A small rectangle put in the margin.\label{rectangle-A}}
\end{marginfigure}

\blindtext[2]
\newpage
\blindtext[1]

\begin{marginfigure}
    \mfincludegraphics[width=1.2\textwidth]{example-image-a}
    \caption{A small rectangle put in the margin.\label{rectangle-B}}
\end{marginfigure}

\blindtext[2]

\newpage\mbox{}

\end{document}

enter image description here

0

You could just make \marginparwidth larger and achieve the same effect without all the overfull \hbox warnings.

\documentclass{caesar_book} 
% -- use dummy graphics
\usepackage{mwe} 
%auto generate the bib file
\usepackage{filecontents} 
% -- language: English -- 
\usepackage[english]{babel}
% -- biblatex --
\usepackage[backend=biber,style=philosophy-classic]{biblatex} % xxx
% the .bib file with the references
\usepackage{blindtext}

\setlength{\marginparwidth}{1.2\marginparwidth}
% to center marginpar in margin given \marginparsep
%\setlength{\marginparwidth}{\dimexpr \paperwidth-\textwidth-\oddsidemargin-1in-2\marginparsep}

\begin{document}
\section*{Scaling a marginfigure in the direction of a marginside}
\blindtext[1]
\begin{marginfigure}%
    \includegraphics[width=\textwidth]{example-image-a}%
    \caption{A small rectangle put in the margin.\label{rectangle}}%
\end{marginfigure}%
\blindtext[2]
\newpage
\blindtext[1]
\begin{marginfigure}%
    \includegraphics[width=\textwidth]{example-image-a}%
    \caption{A small rectangle put in the margin.\label{rectangle}}%
\end{marginfigure}%
\blindtext[2]
\end{document}

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.