2

This is "messed up" and does not have the figure environment:

This is "messed up" and does not have the figure environment

This is "not messed up" and has the figure environment:

This is "not messed up" and has the figure environment

What is causing this?

Thanks!!!

I am setting up a photobook and have everything working except the left pages with included graphics. Graphics on the right side have the bindingoffet, just not on the left side. All text sections and title pages have offset.

\documentclass[openright,twoside,12pt]{book}

Using these commands to insert images:

\newcommand{\addphoto}[1]{
\begin{figure}
\vspace*{.5cm}
\centering
\includegraphics[scale=1]{#1}
\newpage
\end{figure}
}

Which uses these packages:

\usepackage[bindingoffset=0.75in]{geometry}
\usepackage{graphicx}

Inserting test photos after text sections like this:

\section{City One}
\pagestyle{fancy}
\lipsum[1-2]
\newpage
\addphoto{gray_rect.jpg}
\addphoto{gray_rect.jpg}
\addphoto{gray_rect.jpg}

Thank you for all help! I don't know how to get the LHS images to be centered while respecting the bindingoffset which is of course needed for printing.

mark

added:

\documentclass[openright,twoside,12pt]{book}
    \usepackage[
    paperwidth=8.5in,
    paperheight=8.5in,
    bindingoffset=0.2in,
    left=1.25in,
    right=1.25in,
    top=1.25in,
    bottom=1.11in,
    includefoot
    ]{geometry}
    \usepackage{graphicx}
    \usepackage[usenames]{xcolor}
    \usepackage{fancyhdr} 
    \renewcommand{\headrulewidth}{0pt}
    \fancyhf{}
    \setlength{\footskip}{45pt}
    \fancyfoot[C]{\textcolor{gray}{\thepage}}
    \pagestyle{fancy}
    \graphicspath{ {images/} }
    \newcommand{\addphoto}[1]{
\begin{figure}
    \vspace*{-.8cm}
    \centering
    \includegraphics[width=5.5in]{#1}
    \newpage
\end{figure}
    }
    \usepackage{lipsum}
    \parindent=0in
    \parskip=12pt
    \setcounter{secnumdepth}{0}
    \usepackage{titlesec}
    \newcommand{\sectionbreak}{\clearpage}
    \let\oldsection\section
    \renewcommand{\section}{\cleardoublepage\oldsection}
    \newcommand{\nosection}[1]{%
    \refstepcounter{section}%
    \addcontentsline{toc}{section}{#1}
    \markright{#1}}
\begin{document}
    \pagestyle{empty}
\tableofcontents
\thispagestyle{empty}
\frontmatter
\section{Forward}
    \lipsum[1-10]
\section{Introduction}
 Add content:
    \lipsum[1-10]
\mainmatter
\pagestyle{fancy}
\section{City One}
    \lipsum[1-3]
\newpage
\addphoto{example-image}
\section{City Two}
    \lipsum[1-2]
\newpage
\addphoto{example-image}
\addphoto{example-image}
\section{City Three}
    \lipsum[1-2]
\newpage
\addphoto{example-image}
\end{document};
mh2000
  • 151
  • 1
    Remove the figure environment from your \addphoto command to start with. It doesn't make any sense at all. – Johannes_B May 01 '18 at 05:48
  • 3
    Your images are not scaled. They are imported with the size they actually have. If the photo is bigger than the textwidth, it will run into the margin. – Johannes_B May 01 '18 at 05:50
  • Thanks Johannes! Yes, the images have to be scaled down a tiny bit and then they work out fine. I'm still puzzled why they looked good on the RHS and not on LH pages. If I take the figure environment out, then my following sections get all scrambled! No, I'm just learning, so I appreciate that I'm probably doing everything really stupidly, but I'm trying. Thanks! – mh2000 May 01 '18 at 06:01
  • A figure environment places the image for you at a good place. But i guess You want to decide where the images are placed in a photo book? – Johannes_B May 01 '18 at 06:04
  • I want to place it on the page vertically where I want it. Horizontally, Just just want it centered. Really, I just added the environment because my sections were totally messing up and that fixed them without really doing anything to my figures. I'm way over my head, but after scaling the images my skeletal book looks pretty tight. Do you know why not having that figure environment set would mess up the following section? – mh2000 May 01 '18 at 06:16
  • 1
    No idea, you posted just snippets. – Johannes_B May 01 '18 at 06:17
  • figure allows latex to take the content out of the text flow and move the content to other pages to help with page breaking so as Johannes says you should not use it here. If you do use it delete the \newpage inside it which is doing nothing as a figure is a box that can not have a page break inside. Please always post complete small documents that people can test not disjointed fragments (you can useexample-image` which is in the distribution for such tests). We can not run your example but presumably latex is warning you about things sticking in to the margin "Overfull box on page ...." – David Carlisle May 01 '18 at 06:40
  • thanks! I edited the comment to put a small chunk of working code. The sections look fine when run as-is, but if you comment out the figure environment, the last two sections get mucked up! Also, just updated to use the example-image so it should run! (Thanks for the patience. I am just learning!) Thanks! – mh2000 May 01 '18 at 06:44
  • Try \raggedbottom – Johannes_B May 02 '18 at 06:31
  • Messed up in your language means: unwanted white space in TeX language :). So ask again for: How to minimize white space between paragraphs when non-floating pictures are present. – Dr. Manuel Kuehner May 02 '18 at 07:19
  • I think the question then becomes how to maintain all the sectional formatting that existed before inserting a figure. So all the sections before were as expected but after inserting the figures all paragraph spacing and justification etc. gets changed. How do I get it back? – mh2000 May 02 '18 at 20:05

3 Answers3

1
  • I have trouble to understand your question. I stripped down your code to a more minimal version.
  • I also removed the \begin{figure} ... \end{figure} stuff as it's useless (as I understand your intention) as already mentioned in the comments.
  • I also think that \vspace*{-.8cm} will cause trouble since you use the same negative vertical distance for every instance of your pictures.
  • Maybe try to use the minimal code I propose and show your problem with the minimal code.

\documentclass{book}
\usepackage{graphicx}
\usepackage{fancyhdr} 

    % OP's command
    \newcommand{\addphoto}[1]{
        %\begin{figure}
        %\vspace*{-.8cm}
        \centering
        \includegraphics[width=5.5in]{#1}
        \newpage
        %\end{figure}
    }
    \usepackage{lipsum}

\begin{document}

    \pagestyle{empty}
    \tableofcontents
    \thispagestyle{empty}
    \frontmatter

\section{Forward}
    \lipsum[1-10]

\section{Introduction}
    Add content:
    \lipsum[1-10]
    \mainmatter
    \pagestyle{fancy}

\section{City One}
    \lipsum[1-3]
    \addphoto{example-image}

\section{City Two}
    \lipsum[1-2]
    \addphoto{example-image}
    \addphoto{example-image}

\section{City Three}
    \lipsum[1-2]
    \addphoto{example-image}

\end{document}
  • Even in your stripped down code, the last two sections are messed up. Run your's with and without and you will see difference! Yeah, I think the \vspace*{-.8cm} has to be there because I am fighting with the figure environment. But I do need to have all my sections formatted the same and correctly. If you have a moment to run your code with and without and tell me why the the last two sections come out so differently, I'd really appreciate it! – mh2000 May 01 '18 at 15:23
  • @mh2000 Please indicate in a Screenshot what you think is messed up. "messed up" is not very specific. Use my code and show what you mean. – Dr. Manuel Kuehner May 01 '18 at 15:29
  • I added screen captures to show what I mean using your reduced code. The sections above the added images are "not messed up." – mh2000 May 02 '18 at 05:13
0

The answer to my original question was simply that without scaling the image to the width of the text, the graphic placement was unpredictable -- so ensure you are scaled to fit inside your margins! The second question regarding using the figure environment, while users here are telling me that it's "useless," others locally (PhD students who use LaTeX all the time) have told me that it is how they always do it. . . so in this case, I guess the answer is, "There's lots of ways to do things in LaTex and as long as you get the desired results, it's all good!"

Best and thanks all!

mh2000
  • 151
0

The following puts the image in a center environment that centers the image horizontally and adds some vertical space.

Also the image is set in natural size unless its width is larger than the line width. In the latter case the image is limited to the line width, see this answer of David Carlisle).

\makeatletter
\def\maxwidth#1{\ifdim\Gin@nat@width>#1 #1\else\Gin@nat@width\fi}
\makeatother

\newcommand{\addphoto}[1]{%
  \begin{center}%
    \includegraphics[width=\maxwidth\linewidth]{#1}%
  \end{center}%
}

The horizontally ragged text is caused by \centering, if it is not used inside a group like the figure environment. Otherwise \centering is active until the end of the document unless overwritten by \raggedright or \raggedleft (or similar commands).

If the image should be used with \centering:

\par % end previous paragraph (it should probably not be centered)
\begingroup % group start to limit the scope of \centering
  \centering
  \includegraphics[width=\maxwidth\linewidth]{...}% see above
  \par % center the pragraph with the image and end paragraph.
\endgroup % group ends
Heiko Oberdiek
  • 271,626
  • Thank you Heiko!! I will play with these tonight! As I said, I've only been doing this for a week and am really trying to learn everything I can to make better books! Much better than fighting with Word for sure!! Best!! – mh2000 May 03 '18 at 22:29