2

I would like to select the top part (50 %) of the PDF document and put two of such documents one after another. The bottom 50 % is blank.

Here an example code which lists two PDF documents side by side, but the font size gets too small.

\documentclass{article} 
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}{0.45\textwidth}
\includegraphics[page=2,width=\textwidth]{{P100C1}.pdf}
\caption{P100 C1.}
\end{subfigure}
%
\begin{subfigure}{0.45\textwidth}
\includegraphics[page=2,width=\textwidth]{{P100C2}.pdf}
\caption{P100 C2.}
\end{subfigure}
\caption{Descriptive statistics.}
\end{figure}

\end{document}

Testing Werner's approach

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}{1\textwidth}
\adjustbox{trim=0 .5\height{} 0 0, clip, width=.3\linewidth} % show top 50\%
    {\includegraphics[page=2,width=\textwidth]{{P100C1}.pdf}}
\caption{P100 C1.}
\end{subfigure}
%
\begin{subfigure}{1\textwidth}
\adjustbox{trim=0 .5\height{} 0 0, clip, width=.3\linewidth}
    {\includegraphics[page=2,width=\textwidth]{{P100C2}.pdf}}
\caption{P100 C2.}
\end{subfigure}
\caption{Descriptive statistics.}
\end{figure}

\end{document}

Output correct (where just decreased size)

enter image description here

Testing Dan's answer

Output: Something is cropped from the sides

enter image description here

TeXLive: 2016
Debian: 8.5

1
  • I don't recognize this syntax for the subfigure environment. What package defines it?
    – Dan
    Nov 21, 2016 at 22:37

2 Answers 2

3

adjustbox provides access to the image dimensions, specifically \height. Use this as part of your trim-and-clip option:

enter image description here

\documentclass{article}

\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}
  \centering

  \includegraphics[width=.3\linewidth]{example-image-a}%
  \qquad
  \includegraphics[width=.3\linewidth]{example-image-b}%

  \bigskip

  \adjustbox{trim=0 .5\height{} 0 0, clip, width=.3\linewidth}
    {\includegraphics{example-image-a}}% Show top 50%
  \qquad
  \adjustbox{trim=0 0 0 .5\height, clip, width=.3\linewidth}
    {\includegraphics{example-image-b}}% Show bottom 50%

  \caption{Figure caption}
\end{figure}

\end{document}

trim=llx lly urx ury trims the image horizontally llx from the left and urx from the right, as well as lly from the bottom and ury from the top.

1
  • 1
    @Masi: You do notice that I use \adjustbox{..., width=.3\linewidth,...}{..} which shrinks the image horizontally to about 1/3 of the line width, right? You're welcome to change this to suit your needs... I thought you knew this; apparently not.
    – Werner
    Nov 21, 2016 at 23:01
3

A combination of viewport and clip options to \includegraphics:

\begin{figure}
\centering
\begin{subfigure}{\textwidth}
% top half of page 2 of X.pdf
\includegraphics[page=2,viewport=72 396 540 720,width=\textwidth,clip]%
  {X.pdf}
\caption{P100 C1.}
\end{subfigure}\\
% bottom half of page 2 of Y.pdf
\begin{subfigure}{\textwidth}
\includegraphics[page=2,viewport=72 72 540 396,width=\textwidth,clip]%
  {Y.pdf}
\caption{P100 C2.}
\end{subfigure}
\caption{Descriptive statistics.}
\end{figure}
2
  • This works! Confirmed. Can the document be zoomed out little this way. It seems that it crops something at the right hand side too. Nov 21, 2016 at 22:53
  • 1
    @Masi You can adjust the viewport data: the numbers represent the coordinates (in postscript points) of the lower left and the upper right of the visible area. To widen it on the right, change the 540 to something larger. I find that viewport doesn't always seem to behave as I would expect. You may have to tinker with it and the other parameters.
    – Dan
    Nov 26, 2016 at 20:29

You must log in to answer this question.

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