1

Background

I keep a personal journal in LaTeX and would like to simplify my document. I made a \partpage command to create my part pages:

My part page

Every part page has the same image. Only their titles are different.

Question:

Is it possible to just use the \part command, and have LaTeX add the image for me? I can then remove my custom command. I looked at this question but don't understand how to integrate it. My attempt has been commented in the MRE. It doesn't seem to do anything; I assume it's because I'm using the book document class.

How do I make this work?

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

\newcommand{\partpage}[1]{%
    \part[#1]{%
        #1
        \begin{center}
            \includegraphics[width=1in]{Triforce1.png}
        \end{center}%
    }
}

%
% My attempt at integrating https://tex.stackexchange.com/a/485938/118490
%
\makeatletter
\def\@partimage{}
\newcommand{\partimage}[2][]{\gdef\@partimage{\includegraphics[#1]{{#2}}}}
\newcommand{\printparttitle}[1]{\parttitlefon #1\vfil\@partimage\vfil\gdef  \@partimage{}}
\makeatother
%
% End attempt
%

\setcounter{secnumdepth}{-2}

\begin{document}
    \partimage[width=1in]{Triforce1.png}
    \partpage{partpage}
    \part[Part Title B]{Embedded \begin{center}\includegraphics[width=1in]{Triforce1.png}\end{center}}
    \part{Part Cmd} 
\end{document}

Using titlesec

I tried to use the titlesec package, which produced this image. This is close; how do I move the image below the text?

\documentclass[11pt]{book}
\usepackage{graphicx, titlesec}

%
% \titleformat{〈command〉}[〈shape〉]{〈format〉}{〈label〉}{〈sep〉}{〈before-code〉}[〈after-code〉]
% command:     \part
% shape:
% format:      \centering
% label:
% sep:         0pt
% before-code: image stuff
% after-code:  can't get to work?
%
\titleformat{\part}{\centering}{}{0pt}{
    \begin{center}
        \includegraphics[width=1in]{./Triforce1.png}
    \end{center}
}

%
% Using after-code: THIS ERRORS
%
%\titleformat{\part}{\Huge\centering}{}{0pt}{}[
%   \begin{center}
%       \includegraphics[width=1in]{./Triforce1.png}
%   \end{center}
%]

\setcounter{secnumdepth}{-2}

\begin{document}
    \part{partpage}
\end{document}
  • titlesec allows you do that. –  Mar 03 '20 at 03:31
  • @Schrödinger'scat I've updated my question. Following https://ctan.org/pkg/titlesec?lang=en I tried \titleformat. Am I on the right track? –  Mar 03 '20 at 05:18

1 Answers1

1

Does this go in the right direction? With the explicit option you can put the title in some environment.

\documentclass[11pt]{book}
\usepackage{graphicx}
\usepackage[explicit]{titlesec}

\titleformat{name=\part}
[block] 
{\Large}
{\thechapter}
{10pt}
{\centering\begin{tabular}{@{}c@{}}
   \Huge\sffamily #1\\
   \includegraphics[width=1in]{example-image-duck}
\end{tabular}}
[]

\setcounter{secnumdepth}{-2}

\begin{document}
\part{partpage}

Some text.
\end{document}
  • I added a little \vspace{10pt} after the #1 to space the text and the picture. This is great. Thanks. –  Mar 03 '20 at 06:00
  • What is \thechapter? I can't find it in the titlesec documentation –  Mar 03 '20 at 06:01
  • @Amy \thechapter is just the chapter number. –  Mar 03 '20 at 06:02