3

There's just THIS TEXT NEEDS TO BE ALIGNED text on one page of my book that's preceded by some vspace value. There's also some WITH THIS TEXT text on another page that's preceded by some vspace value, TEXT BEFORE TEXT THAT NEEDS TO BE ALIGNED text of a different size and an example-image-c image.
I need THIS TEXT NEEDS TO BE ALIGNED and WITH THIS TEXT to be exactly at the same distance from the page's top so, if both pages are stacked together, both texts would be properly aligned to each other.
In my current code I assigned ex values to texts, vspaces and even to the image's height. I hoped that by equaling the total numbers of vertical values of all elements that precede both texts, I'll have the needed texts properly aligned (at the same distance from the page's top), but they're not! What am I doing wrong? Does \begin{titlepage} on one of the pages add some space I am not aware about?

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}
\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[
  SmallCapsFont={EB Garamond SC},
  SmallCapsFeatures={Letters=SmallCaps},
  Ligatures=TeX,
]
\usepackage{microtype}
\usepackage[shortcuts]{extdash}
\usepackage[pagewise]{lineno} 
\usepackage[
  paperwidth=6in,
  paperheight=9in,
  inner=15mm,
  top=15mm,
  outer=20mm,
  bottom=22mm,
  heightrounded,
]{geometry}

\usepackage{lipsum} \setlength{\parskip}{0pt} \usepackage{graphicx} \usepackage[dvipsnames]{xcolor} \usepackage{titlesec}

\titleclass{\chapter}{straight} \titleformat{\chapter}[display]{\filcenter\normalfont\large}{\thechapter.}{6pt}{} \titlespacing*{\chapter}{0pt}{30pt}{10pt plus 10pt}

\begin{document} \pagenumbering{gobble} \frontmatter

% PAGE1 \vspace*{14ex} \begin{center} {\fontsize{4ex}{4ex}\bfseries{THIS TEXT NEEDS TO BE ALIGNED}\par} % TEXT THAT NEEDS TO BE ALIGNED \end{center} \vspace{9ex}
\AddToHook{shipout/background}{% \put(0mm,-240mm){\ifnum\value{page}=0 \includegraphics[width=200mm,height=250mm,keepaspectratio]{example-image-a}\fi} \put(60mm,-200mm){\ifnum\value{page}=0 \includegraphics[width=60mm,height=60mm,keepaspectratio]{example-image-b}\fi} } \clearpage

% TITLE PAGE \begin{titlepage} \centering \vspace*{6ex} {\scshape\fontsize{6ex}{6ex}{TEXT BEFORE TEXT THAT NEEDS TO BE ALIGNED}\par} \begin{center} \includegraphics[height=2ex,keepaspectratio]{example-image-c} \end{center} {\fontsize{4ex}{4ex}\bfseries{WITH THIS TEXT}\par} % TEXT THAT NEEDS TO BE ALIGNED \vspace{9ex} {\scshape\footnotesize{SOME RANDOM TEXT}\par} \vspace{3ex} {\scshape\footnotesize{SOME RANDOM TEXT}\par} \vspace{9ex} {\large SOME RANDOM TEXT\par} \vspace{50ex} {\footnotesize SOME RANDOM TEXT\par} \vspace{0ex} {\footnotesize SOME RANDOM TEXT\par} \vspace{0ex} {\footnotesize SOME RANDOM TEXT\par} \vspace{0ex} \vfill \title{SOME TITLE} \author{SOME AUTHOR} \date{} \end{titlepage} \clearpage

\mainmatter

\pagenumbering{arabic}

\chapter{CHAPTER ONE} \lipsum[1-1]

\end{document}

Simon Dispa
  • 39,141
tryingout
  • 115

1 Answers1

3

This approach uses a box with the material above "WITH THIS TEXT" to calculate the vertical space needed before "THIS TEXT NEEDS TO BE ALIGNED" to align the two sentences.

c

(Using \documentclass[11pt,oneside,openany]{book} only to display the two pages side by side when open the pdf file.)

UPDATED after follow-up questions.

\documentclass[11pt,oneside,openany]{book}

\usepackage[english, russian]{babel} \usepackage{fontspec} \setmainfont{EB Garamond}

\usepackage{microtype} \usepackage[shortcuts]{extdash} \usepackage[pagewise]{lineno}

\usepackage[ paperwidth=6in, paperheight=9in, inner=15mm, top=15mm, outer=20mm, bottom=22mm, heightrounded, showframe % added showframe to display the margins ]{geometry}

\usepackage{lipsum} \setlength{\parskip}{0pt} \usepackage{graphicx} \usepackage[dvipsnames]{xcolor} \usepackage{titlesec}

\titleclass{\chapter}{straight} \titleformat{\chapter}[display]{\filcenter\normalfont\large}{\thechapter.}{6pt}{} \titlespacing*{\chapter}{0pt}{30pt}{10pt plus 10pt}

% ************************************* added <<<<<< \newsavebox{\upperspace} \savebox{\upperspace}{% \begin{minipage}[b][][t]{\textwidth}
\begin{titlepage} \centering \vspace*{6ex} {\scshape\fontsize{2ex}{2ex}\selectfont TEXT BEFORE TEXT THAT NEEDS TO BE ALIGNED\par} \begin{center} \includegraphics[height=2ex,keepaspectratio]{example-image-c} \end{center} \end{titlepage} \end{minipage} }

\newlength{\hhbox} \settoheight{\hhbox}{\usebox{\upperspace}} % *************************************

\begin{document}

\pagenumbering{gobble} \frontmatter

% PAGE1 \vspace*{\dimexpr\the\hhbox-1em}% changed <<<<<<<<< {\centering

{\fontsize{4ex}{4ex}\selectfont\bfseries THIS TEXT NEEDS TO BE ALIGNED\par}% TEXT THAT NEEDS TO BE ALIGNED

\AddToHook{shipout/background}{% \put(0mm,-0mm){\ifnum\value{page}=0 \includegraphics[width=200mm,height=250mm,keepaspectratio]{example-image-a}\fi} \put(60mm,-0mm){\ifnum\value{page}=0 \includegraphics[width=60mm,height=60mm,keepaspectratio]{example-image-b}\fi} }}

\clearpage

% TITLE PAGE \begin{titlepage} \centering \usebox{\upperspace}

{\fontsize{4ex}{4ex}\selectfont\bfseries WITH THIS TEXT\par} % TEXT THAT NEEDS TO BE ALIGNED
\vspace{9ex}
{\scshape\footnotesize{SOME RANDOM TEXT}\par}
\vspace{3ex}
{\scshape\footnotesize{SOME RANDOM TEXT}\par}
\vspace{9ex}
{\large SOME RANDOM TEXT\par}
\vspace{50ex}
{\footnotesize SOME RANDOM TEXT\par}
\vspace{0ex}
{\footnotesize SOME RANDOM TEXT\par}
\vspace{0ex}
{\footnotesize SOME RANDOM TEXT\par}
\vspace{0ex}
\vfill
\title{SOME TITLE}
\author{SOME AUTHOR}
\date{}

\end{titlepage} \clearpage

\mainmatter

\pagenumbering{arabic}

\chapter{CHAPTER ONE} \lipsum[1-1]

\end{document}

When using \fontsize{}{}\selectfont inside a group, it is necessary to end the paragraph before closing the group.

While the fontsize is updated when issuing \selectfont the new baselineskip is only is updated when the paragraph is ended using \par, or by a blank line.

See How does \fontsize{}{} work?

Simon Dispa
  • 39,141
  • Wow! Great! Solved my problem. Couple of things though. 1. I had to remove all \centering commands from your code and wrap it in \begin{center} and \end(center) instead, otherwise the whole text until the end of the book gets center-aligned. 2. I experimented and changed the font size and image's size and the alignment stays intact (perfect!) but what in your code governs that? 3. What does \begin{minipage}[b][][t]{0.8\linewidth} do? Why is it exactly 0.8\linewidth? 4. What does \vspace*{\dimexpr\the\hhbox-1em} do? Why can't it be a simple numeric value? Thanks for your help! – tryingout Apr 15 '22 at 07:39
  • And by the way, how do I get to see that red line across two side-by-side pages to check the alignment? showframe only exposes the outer frame. – tryingout Apr 15 '22 at 11:46
  • @tryingout The red line was drawn over a captured jpg of the pdf with an external program (free, FastStone Image Viewer). Question(4) and (2) A single numeric value will not adapt to changes in fonts or image size. The code measures the height of the material above every time and then applies the vertical shift. – Simon Dispa Apr 15 '22 at 13:20
  • @tryingout I corrected the problem with centering. Thank you for your feedback. The minipage allows to put in a box environments like titlepage and center (they add spaces before and after) in order to measure the total height in a single operation. To learn how \begin{minipage}[b][][t]{\textwidth} works see https://latexref.xyz/minipage.html#index-minipage-environment – Simon Dispa Apr 15 '22 at 13:53
  • Useful info. Learned what those parameters after {minipage} are. Can you point me to where I can learn about \vspace*{\dimexpr\the\hhbox-1em} command? I’m only used to numeric values of vspace and would like to know how that command affects the text. – tryingout Apr 15 '22 at 15:26
  • @tryingout Without the * the skip is always discarded at the start of the page, and with the * it is not discarded. Also read https://latexref.xyz/Expressions.html – Simon Dispa Apr 15 '22 at 18:57