2

I have large squared figures. I want to align them to left or right edge of the page. In other words they should occupy inner/outer (or "centered" both margins)margin and also on top margin.

I'm aware of printing bleed risk.

Is there any automatic solution?

My primitive attepmts:

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage{changepage}
\usepackage{lipsum}

\newcommand{\adjustimg}{% Horizontal adjustment of image \checkoddpage% \ifoddpage\hspace{-4.5cm}\else\hspace{4.5cm}\fi% } \newcommand{\centerimg}[2][width=\textwidth]{% Center an image \makebox[\textwidth]{\adjustimg\includegraphics[#1]{#2}}% }

\begin{document} \mbox{} \par \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%<- calculaded top margin align \noindent\centerimg[scale=0.5]{example-image-a}

\lipsum[2]

\newpage

\mbox{} \par \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%<- calculated top margin align \noindent\centerimg[scale=0.5]{example-image-b}

\lipsum[2]

\end{document}

Edit: Added top margin align: How to include a picture over two pages, left part on left side, right on right (for books)?

ReRunner
  • 471
  • What would you consider "an automatic solution?" Would that be using \includegraphics rather than \centerimg? – Werner Sep 15 '21 at 17:27
  • In my example, the size of the margins is entered manually, based on the page size. Can this be automatically calculated considering the page or image size? – ReRunner Sep 15 '21 at 17:35
  • 2
    You want the figures on right and left borders of the page and also on the top border? In your question you mention topmargin. – Simon Dispa Sep 15 '21 at 19:22
  • And yes, the margins can be calculated automatically, depending on whether on an even or odd page. The left margin is easy, while the right is whatever remains of \paperwidth. Same for the bottom margin. See also tikzpagenodes. – John Kormylo Sep 16 '21 at 00:23

1 Answers1

1

\makebox[<width>][<align>]{<stuff>} does provide an <align>ment character to push content either left or right:

enter image description here

\documentclass{book}

\usepackage[demo]{graphicx} \usepackage{changepage} \usepackage{lipsum}

\newcommand{\centerimg}[2][width=\textwidth]{% Center/align an image \checkoddpage \makebox[\linewidth][\ifoddpage l\else r\fi]{\includegraphics[#1]{#2}}% }

\begin{document}

\noindent\centerimg[scale=0.5]{example-image-a}

\lipsum[2]

\newpage

\noindent\centerimg[scale=0.5]{example-image-b}

\lipsum[2]

\end{document}

Werner
  • 603,163