3

I am trying to put an image into the same page as the \part header, something like a sub-cover.

I tried something along the lines:

\documentclass[10pt,ebook,italian,onecolumn,oneside,titlepage,extrafontsizes]{memoir}
\usepackage[italian]{babel}
\usepackage{graphicx}
...
\title{Book Title}
\begin{document}
\frontmatter
\maketitle
\mainmatter
\chapterstyle{companion}
\tableofcontents
\part{Part I Title}
\includegraphics[width=\linewidth]{PartIcover.jpg}
\chapter{First Chapter TItle}

This does not work well for two reasons:

  • image is not right after "Part I Title", but on next page.
  • in image page I get a spurious "INDEX #" header (which is not present in \part page, of course)

Is it possible to achieve the desired effect? ("Part I Title" on top of page and image below it).

If so: how?

Note: I am almost a newbie to LaTeX, please be lenient.

Update: following advice in comments I made the following; working, but fragile to say the least:

\documentclass[...]{memoir}
\usepackage[italian]{babel}
\usepackage{graphicx}
...
\def\@partimage{}
\newcommand{\partimage}[2][]{\gdef\@partimage{\includegraphics[#1]{#2}}}
\renewcommand{\printparttitle}[1]{\parttitlefont #1\vfil\@partimage\vfil\gdef\@partimage{}}
\makeatother
...
\title{Book Title}
\begin{document}
\frontmatter
\maketitle
\mainmatter
\chapterstyle{companion}
\tableofcontents
\partimage[width=210pt]{PartIcover.jpg}
\part{Part I Title}
\includegraphics[width=\linewidth]{PartIcover.jpg}
\chapter{First Chapter Title}

This is very fragile because I need to hand-compute remaining height after \part title.

I saw this answer, but I'm unsure how to use it in the above code.

ZioByte
  • 285
  • take a look at https://tex.stackexchange.com/questions/40602/redefine-memoir-part-to-allow-image –  Apr 20 '19 at 22:17
  • @KJO: I had already tried that and it didn't work for me, but it turns out it was a my mistake: Image was too high to fit if scaled at [width=\linewidth]. What is the right spell to say "scale to fit in page"? (I currently put [width=210pt], but that is very fragile). – ZioByte Apr 20 '19 at 22:45
  • height=\textheight. Try e.g. \documentclass{article} \usepackage{graphicx} \begin{document} \includegraphics[angle=90,height=0.9\textheight]{example-image-duck} \end{document}. –  Apr 21 '19 at 00:55
  • See also https://tex.stackexchange.com/questions/485144/how-to-place-part-titles-to-top-of-paper/485154?r=SearchResults&s=1|0.0000#485154 – John Kormylo Apr 21 '19 at 01:55
  • @marmot: it does not work as-is; apparently \textheight is the full height of text area, while I need "remaining height in current page". Any hint where I should look for that kind of data? I have seen https://tex.stackexchange.com/a/373312/167976 but I'm unsure how to use it in my case. I will update question. – ZioByte Apr 21 '19 at 08:25
  • @marmot s approach is generally robust since in theory for a given page content not to float to next the page text height is the target boundary condition. By allowing say 5% for title we are left with 0.95 of text height for the image initially irrespective of aspect (so for a fixed landscape image) the secondary limit needs be text width thus in many cases leaving some following whitespace for text or second image. –  Apr 21 '19 at 09:48

1 Answers1

2

Thank you for essentially using the code I posted to SE about 40602 and 452089.

It is not clear to me whether you will be using the same or different graphics for each \part and how you want them placed on the page --- to fill the \textwidth or take up all the space below the part title text (you might not be able to have both). However, this may help (less any typos)

\documentclass{memoir}
\usepackage{graphicx}
\makeatletter
\def\@partimage{}
\newcommand{\partimage}[2][]{\gdef\@partimage{\includegraphics[#1]{#2}}}
\renewcommand{\printparttitle}[1]{\parttitlefont #1\vfil\@partimage\vfil\gdef  \@partimage{}}
\makeatother
\begin{document}
\partimage[height=0.5\textheight,width =\textwidth,keepaspectratio]{example-image-duck-portrait.pdf}
\part{A Part}
\partimage[height=0.5\textheight,width=\textwidth,keepaspectratio]{example-image-duck.pdf}
\part{Another Part}
\partimage[height=0.5\textheight,width=\textwidth,keepaspectratio]{example-image-duck-portrait.pdf}
\part{Another Part}
\partimage[height=0.5\textheight,width=\textwidth,keepaspectratio]{example-image-duck-portrait.pdf}
\part{The Third}
\end{document}

The above will fit an illustration on the same page as the \part heading constrained to be within the dimensions of half the \textheigt and the \textwidth while maintaining the aspect ratio of the illustration. The example illustrates how a different illustration can be applied to each \part.

GOM

mapf
  • 207
Peter Wilson
  • 28,066
  • Peter a few typo's snuck in so need … \includegraphics[#1]{{#2}}} second example-image is a Puck? last example unknown=keepadspectratio –  Apr 21 '19 at 20:42
  • Many thanks for Your code; it works perfectly in plain latex->PDF, but now I'm trying to produce epub using tex4ebook and images simply disappear; can You help with that? – ZioByte Apr 22 '19 at 10:46
  • 1
    @KJO Thank you. Hopefully I have corrected the typos you pointed out. I have learned over the years that one cannot proofread ones own text.. – Peter Wilson Apr 22 '19 at 19:49
  • @ZioByte Sorry, I can't help with that. Perhaps you could ask another question related to tex4book. – Peter Wilson Apr 22 '19 at 19:52
  • @PeterWilson I agree it is always easier to find fault with "others" work :-) –  Apr 22 '19 at 20:53