![如何在小页面环境中使文本垂直居中?](https://linux22.com/image/458905/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%B0%8F%E9%A1%B5%E9%9D%A2%E7%8E%AF%E5%A2%83%E4%B8%AD%E4%BD%BF%E6%96%87%E6%9C%AC%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%EF%BC%9F.png)
我正在写我的简历,以下是有关我的问题的 MWE:
\documentclass[11 pt,oneside,a4paper,titlepage]{article}
\usepackage{graphicx}
\RequirePackage{graphbox}
\usepackage{calc}
\usepackage{lipsum} % dummy text
\usepackage{adjustbox} % to a better alignement of text
\begin{document}
\adjustbox{valign=t}{%
\begin{minipage}{11.3cm}
\vspace*{0.4cm}
% Certificates
\section*{CERTIFICATES}
\adjustbox{valign=t}{\begin{minipage}{2cm}
\begin{center}
\includegraphics[keepaspectratio,height=0.8cm]{Logos/logo_PP.pdf}
\end{center}
\end{minipage}}
\hfill \vline \hfill
\adjustbox{valign=t}{\begin{minipage}{9cm}
\scriptsize
Microsoft Office Specialist PowerPoint 2016 (\textit{Microsoft, 2019})
\end{minipage}}
\vspace*{0.2cm}
\end{minipage}}
\end{document}
我需要将文本垂直对齐到垂直线,你能帮我吗?
答案1
如果您指定了小页面的高度(可选参数),则可以将内容相对于空间本身对齐。第一个参数 [c] 将基线置于每个小页面的中心(无论内容如何)。第三个参数 [c] 将内容相对于顶部和底部居中。您也可以将 [t] 或 [b] 或 [s] 用于第三个参数,而无需更改 s \hrule
。
\documentclass[11 pt,oneside,a4paper,titlepage]{article}
\usepackage{graphicx}
\RequirePackage{graphbox}
\usepackage{calc}
\usepackage{lipsum} % dummy text
%\usepackage[export]{adjustbox} % not used
\begin{document}
\begin{minipage}{11.3cm}
\vspace*{0.4cm}
% Certificates
\section*{CERTIFICATES}
\hrule % show top of group
\begin{minipage}[c]{2cm}
\centering
\includegraphics[height=0.8cm]{example-image}%{Logos/logo_PP.pdf}
\end{minipage}%
\hfill \vline \hfill
\begin{minipage}[c][0.8cm][c]{9cm}
\scriptsize
Microsoft Office Specialist PowerPoint 2016 (\textit{Microsoft, 2019})
\end{minipage}
\hrule% show bottom of broup
\vspace*{0.2cm}
\end{minipage}
\end{document}
答案2
我对您的 MWE 有点迷茫,因此我重写了文档正文代码,在我看来,这更清晰/更合乎逻辑。
编辑:
在第一个答案版本中,我忽略了图像和文本之间的垂直线。没有添加。也被minipage
替换为tabular
表格:
\documentclass[11pt,oneside,a4paper,titlepage]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\usepackage{array}
\usepackage[export]{adjustbox} % for vertical alignment of image
\begin{document}
% Certificates
\section*{CERTIFICATES}
\begin{center}
\begin{tabular}{w{c}{20mm} | w{l}{98mm}}
\includegraphics[height=0.8cm, valign=m]{example-image-duck}%{Logos/logo_PP.pdf}
& \small
Microsoft Office Specialist PowerPoint 2016 (\textit{Microsoft, 2019})
\end{tabular}
\end{center}
\end{document}
(红线表示文本框边框)