1

I'm trying to include a pdf document into my main LaTeX document (all my publications into my manuscript), but I want to keep the same page numbering throughout. I'm using the pdfpages package as follows,

\RequirePackage{pdfpages}

\includepdf[pages={-}, % all pages
pagecommand={\thispagestyle{fancy}} % continue page numbering
]{file.pdf}

For most files this works great, but for one particular file this happens:

Input doesn't fit, trails off the page

Definitely not what I wanted, so I removed all excess margins by applying

 pdfcrop file.pdf file-pdfcrop.pdf

And update the options as follows,

\includepdf[pages={-}, % all pages
width=\textwidth, % full text-width
frame=true, % for debugging
pagecommand={\thispagestyle{fancy}} % continue page numbering
]{file-pdfcrop.pdf}

This works fine but not exactly aesthetically pleasing for some pages. As the pages in file.pdf have been cropped to various sizes.
Input fits, but centered

Is there any way to force \includepdf to be positioned to the top of the page instead of the default centering?

PS This is my first post on tex.stackexchange, so be gentle ;-)

  • if it's only one page you can try include it as figure with option [t] but i think it's better if you solve your first problem without croping the pdf file – touhami Aug 6 '15 at 6:45
  • Each file is several pages, and usually it's the references (last page) that gets all messed up (see pic). I'm doing this for all of my publications, so I'm hoping for magic formula that works on all files the same. Especially since my original files were published on various formats. – tungufoss Aug 6 '15 at 11:16
2

I figured I might as well just use pdfcrop to same sized margins and using a bash script to apply it to all of my pdfs

for file in $DIRECTORY/*.pdf; do
  # Process $file
  echo $file
  # Find bounding boxes
  pdfcrop --verbose $file tmp.pdf | grep "%%HiResBoundingBox:" > bbox; 
  # First page has the largest bounding box
  largest=`echo $(head -n 1 bbox)| cut -d':' -f 2` 
  # Crop $file
  pdfcrop $file tmp.pdf --bbox "$largest"
  mv tmp.pdf $file
done
rm bbox

Finally, success! Final result

  • Did you find a LaTex solution for this? – vanboom Mar 6 '18 at 18:13
  • Nope. I remember finding only solutions for 1-page pdfs. Which didn't solve my particular problem. Once I found a good-enough workaround I was happy, although I'd have preferred a built-in LaTeX solution so I wouldn't need to keep an extra copy of the included files without margins. – tungufoss Mar 8 '18 at 10:32

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.