
THIS TEXT NEEDS TO BE ALIGNED
我的一頁上只有文本book
,前面有一些vspace
值。另一個頁面上還有一些WITH THIS TEXT
文本,前面有一些vspace
值、TEXT BEFORE TEXT THAT NEEDS TO BE ALIGNED
不同大小的文本和example-image-c
圖像。
我需要THIS TEXT NEEDS TO BE ALIGNED
和WITH THIS TEXT
與頁面頂部的距離完全相同,因此,如果兩個頁面堆疊在一起,兩個文字將彼此正確對齊。
在我當前的程式碼中,我分配ex values
給文本,vspaces
甚至分配給圖像的高度。我希望透過等於兩個文字之前的所有元素的垂直值總數,我將正確對齊所需的文字(與頁面頂部的距離相同),但事實並非如此!我究竟做錯了什麼?\begin{titlepage}
其中一頁是否增加了一些我不知道的空間?
% !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}
答案1
此方法使用包含「WITH THIS TEXT」上方材料的方塊來計算「THIS TEXT NEEDS TO BE ALIGNED」之前所需的垂直空間,以對齊兩個句子。
( \documentclass[11pt,oneside,openany]{book}
僅用於開啟 pdf 檔案時並排顯示兩頁。)
更新後續問題之後。
\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}
在群組內使用時\fontsize{}{}\selectfont
,需要在關閉群組之前結束段落。
\selectfont
雖然字體大小在發布新版本時更新,baselineskip
但僅在段落使用 , 或空白行結束時更新\par
。