文字垂直居中,準確無誤

文字垂直居中,準確無誤

我嘗試了該論壇上給出的兩種解決方案。他們都沒有真正將文本居中。我在下面放了一張。已經差很多了我希望它居中測量從文字區塊(?...寫入普通文字的矩形)到字母高度的中間(大寫字母很好)。

%\documentclass[a4paper, 11pt, oneside]{book} % A4 paper size, default 11pt font size and oneside for equal margins

%PACKAGES
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{fancyhdr}
\usepackage[paperwidth=6in, paperheight=9in, showframe]{geometry}

\fancypagestyle{clearstyle}{\fancyhead{}\fancyfoot{}}

\begin{document}
\begin{center}
\vspace*{\stretch{1}}
{\Huge \textbf{\textit{Too Low}}\par}
\vspace*{\stretch{1}}
\end{center}

\clearpage 
\end{document}

答案1

只需使用這個(儘管在我看來,黃金比例會更好):

\begin{center}
\null\vspace*{\stretch{1}}
{\Huge \textbf{\textit{Too Low}}\par}
\vspace*{\stretch{1}}\null
\end{center}

\clearpage

在此輸入影像描述

這是一個程式碼,其中包含stretch近似黃金比例的值(對於文字區域):

\begin{center}
\null\vspace*{\stretch{1}}
{\Huge \textbf{\textit{Too Low}}\par}
\vspace*{\stretch{1.72}\null
\end{center}

在此輸入影像描述

答案2

您可以使用文字位置將文字絕對放置在網格中間 - 但是,當文字位於頁面中間居中時,它在視覺上看起來太低了。

我沒有補償文字方塊的高度,因此文字可能應該高出大約 2 毫米。

在此輸入影像描述

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

\usepackage{libertine}
\usepackage[absolute]{textpos}
\TPGrid[-7mm,0mm]{210}{290}

\begin{document}
\begin{textblock}{54}(78,145)
{\Huge \textbf{\textit{Too Low gg}}\par}
\end{textblock}
\end{document}

答案3

下面我用的是eso-pic\AtTextCenter將物件放置在文字區塊的中心。由於物件是文本,放置在基線上,將其放置在中間(或以負距離升高)有助於使其在頁面上垂直居中。

在此輸入影像描述

\documentclass{book}

%PACKAGES
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{eso-pic}
\usepackage[paperwidth=6in, paperheight=9in, showframe]{geometry}

\begin{document}

\pagestyle{empty}

\mbox{}% Just to put something on the page
\AddToShipoutPicture*{%
  \AtTextCenter{%
    \makebox[0pt]{\raisebox{\dimexpr-.5\height+.5\depth}{\fbox{\Huge\bfseries Lazy fox}}}%
  }%
}

%\clearpage% Ship out page

\end{document}

當然,您可以刪除\fbox和其他不適合您的使用的元素。

相關內容