Graphics, Figures & TablesDoes \includegraphics like {geometry}?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Does \includegraphics like {geometry}?

Post by krz »

Hi,
Yes, I know I was writing about it a week ago and you helped me, but I can't stop to think about it. My problem appears when I want to add graphics into my document. The bottom margin is smaller on the pages with images than on the other.
I took my document to pieces and observed there was a problem even in so simply document like that:

Code: Select all

\documentclass[11pt]{book}
\usepackage[demo]{graphicx}

\usepackage[
  centering,
  papersize={160mm,235mm},
  text={125mm,190mm},
]{geometry}

\setlength{\parskip}{0pt}
\setlength{\parindent}{11pt} 

\usepackage{lipsum}

%----------------------------------

\begin{document}

\lipsum

\begin{figure}
{\begin{center}
\includegraphics{demo}
\end{center}}
\end{figure}

\lipsum

\end{document}
When I remove {geometry} or \setlength{\parskip}{0pt} everything is ok. When I bring one of them back, the problem appears again.
Please, copy it and check if you get the same problem. I use TeXshop.
Thanks!
krz
Last edited by krz on Wed Jan 05, 2011 12:46 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Does \includegraphics like {geometry}?

Post by meho_r »

The behaviour you're suspicious about is perfectly normal. Take into account the following:

1. You specified text area in absolute units. You should be aware that height=190mm doesn't necessary contain an integral number of lines, which means that the last lines on different pages wouldn't necessary be aligned. Try changing slightly the height and observe the last line on the first page (with \raggedbottom activated, of course). If you want an integral number of lines, try using lines option to geometry, as I did in the code below. Compare the result with the one you get using millimeters.

2. \parskip and \parindent are not the cause of this behaviour you consider a problem. Test the code below, comment these two out then activate them again and you'll notice that nothing changes. Also, comment out \raggedbottom and observe the page containing the image, you'll notice that this time the last line is aligned with those on other pages (i.e., it's exactly at the bottom of text area), but the space between the image and the first line is enlarged.

3. The height of the image included does matter. Try changing it and observe changes.

Code: Select all

\documentclass[11pt]{book}
\usepackage[demo]{graphicx}

\usepackage[
  showframe,% === added
  centering,
  papersize={160mm,235mm},
  %text={125mm,190mm},
  lines=40,% === added
  textwidth=125mm% === added
]{geometry}

\raggedbottom% === added

%\setlength{\parskip}{0pt}
%\setlength{\parindent}{11pt} 

\usepackage{lipsum}

%----------------------------------

\begin{document}

\lipsum

\begin{figure}
{\begin{center}
\includegraphics[height=2.6cm]{demo}% === try changing the height of the figure
\end{center}}
\end{figure}

\lipsum

\end{document}
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Re: Does \includegraphics like {geometry}?

Post by krz »

Thanks, meho_r! Thanks for a bit of theory. I didn't realise absolute units might cause this problem, but it's logical. :)
I started to change height of text. Problems die out when I set 200mm or 190.5mm for example.
I'll experiment with {geometry} and its options and see what is good for me. I tired line option for example and it works good. The option showframe is really usefull too.
By the way, do you know if memoir class resolve layout problems better? Somebody (maybe you) told me here it's good to use this class. The manual is really huge, but maybe it's worth to study it.
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Does \includegraphics like {geometry}?

Post by meho_r »

I'm not sure if there is a satisfactory automatic solution for this problem. A possible way would be to calculate everything: from sectioning units, their size, spacings before and after, using \baselineskip as the base unit for vertical sizes etc., but that might be overkill. I asked somehow the similar question a long time ago, about optimal page design. There was no answer. So, to have everything aligned perfectly, you'll have to include manual work, some planning and lot of experimenting.

I'm not sure if memoir would provide any advantage geometry-side, but it definitely makes life a lot easier. Just skim through the manual to see if it's for you. I personally use it for everything I do with LaTeX. Also, it is worth mentioning koma-script, another great document class you might consider. It has another very interesting approach to defining page size and other elements.

I'll mention also something you might find interesting. During creation of "The LaTeX Companion", 2nd edition, some manual work was required: text on 10% of pages was rewritten in order to avoid bad page or line breaks, there was 45 long spreads (one line more on facing pages than normal), 25 short spreads (one line less on facing pages than normal), 230 forced page breaks, 400 adjustments to the vertical spacing and 100 other manual adjustments. The book has about 1000 pages, so this wasn't a small task. This shows that, even if one is expert, s/he'll have to do manual work from time to time to get things done properly. It's unavoidable.
Post Reply