0

I would like to place one large image into the horizontal and vertical center of each page in a multi-page document and simultaneously have each image placed into a thin, black frame. Each image shall be oversized somewhat with regard to the mdframe such that the frame over-prints the image.

Why is the following code failing on all three counts (horizontal alignment, vertical alignment, and frame)?

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{mdframed}
\usepackage{mwe}
\begin{document}

\vfill
\begin{mdframed}[linewidth=1pt, leftmargin=0cm, rightmargin=0cm, align=left]
    \centering
    \includegraphics[width=1.25\textwidth]{example-image}
\end{mdframed}
\vfill
\pagebreak

\vfill
\begin{mdframed}[linewidth=1pt, align=center]
    \centering
    \includegraphics[width=1.25\textwidth]{example-image}
\end{mdframed}
\vfill
\pagebreak

\vfill
\begin{mdframed}[linewidth=1pt, align=right]
    \centering
    \includegraphics[width=1.25\textwidth]{example-image}
\end{mdframed}
\vfill

\end{document}

Edit 1: Desired outcome with regard to image and frame: enter image description here

9
  • 1
    \centering will not center an over-full box, over full boxes always overflow on the right, but it isn't clear what you want the mdframed to do, why not simply \fbox or \frame ? you are specifying alignment in the options then over-riding that with \centering and then adding over-sized content? You could use negative space but then the image would over-print the rule to the left and under-print the rule to the right? Commented Jun 4, 2021 at 19:33
  • white space is discarded at a page break so you want \vspace*{\fill} just as horizontal space is dropped at a line break unless you use \hspace* Commented Jun 4, 2021 at 19:35
  • @DavidCarlisle My goal is to have an image that overprints the mdframe equally on all four sides. Commented Jun 4, 2021 at 19:36
  • I guess my answer is not what you want then as I guessed wrong, but I don't understand, if you draw a frame and then over-print it, that is the same as not drawing it at all. Commented Jun 4, 2021 at 19:41
  • @DavidCarlisle "Overprint" may not the correct term. My goal is to have an image that exceeds the frame equally on all four sides while the black frame is still visible. Commented Jun 4, 2021 at 19:44

1 Answer 1

1

To answer your question as to why the code in the question did not work,

Vertical centering is not achieved because space is discarded at the top of a page, just as inter-word space is dropped at al linebreak, so you want \vspace*{\fill} not \vfill where the * form prevents the space being dropped.

The frame is not tight to the image as essentially you are wrapping a parbox of width \textwidth so the frame is around that. The image makes the box over-full but that does not change the frame size.

Horizontal centering is not achieved as \centering does not center over-full boxes, the overflow is always on the right.


I'm not sure I understood the requirements but perhaps


plan B

enter image description here

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}

\begin{document}

\centering

\linethickness{2pt}

\vspace*{\fill}

\sbox0{\includegraphics[width=1.25\textwidth,trim=10pt 10pt 10pt 10pt]{example-image}}

\makebox[0pt]{\usebox{0}\llap{\frame{\phantom{\usebox0}}}}

\vspace*{\fill}


\end{document}

plan A

enter image description here

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}

\begin{document}

\centering

\vspace*{\fill}

\makebox[\textwidth][l]{\frame{\includegraphics[width=1.25\textwidth]{example-image}}}

\vspace*{\fill}

\pagebreak

\vspace*{\fill}

\makebox[\textwidth][c]{\frame{\includegraphics[width=1.25\textwidth]{example-image}}}

\vspace*{\fill}

\pagebreak

\vspace*{\fill}

\makebox[\textwidth][r]{\frame{\includegraphics[width=1.25\textwidth]{example-image}}}

\vspace*{\fill}



\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .