\begin{center}
\textbf{\Large\uppercase{Note - 1}}\\
\vspace{24pt}
\textbf{\Large\uppercase{Data analysis}}
\end{center}
使用这段代码,我能够获得水平居中对齐。但我还希望文本垂直对齐。
我希望垂直对齐方式是垂直中心位于这两条线的中间。如何在 latex 中做到这一点?
@Patrick Ferguson 的结果:
<-- 结果
我使用的代码是
\documentclass[12pt, a4paper]{article}
\usepackage[left=3.3cm,right=2.3cm,top=2.3cm,bottom=2.3cm, footskip=42pt]{geometry}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
[remember picture, overlay] \draw[line width=3pt] ($(current page.north west)+(2.5cm,-1.5cm)$) rectangle ($(current page.south east)+(-1.5cm,1.5cm)$);
[remember picture, overlay] \draw[line width=1pt] ($(current page.north west)+(2.6cm,-1.6cm)$) rectangle ($(current page.south east)+(-1.6cm,1.6cm)$);
\end{tikzpicture}
\phantom{*} % \phantom => invisible
\vfill
\begin{center}
\textbf{\Large\uppercase{Note - 1}}\\
\vspace{24pt}
\textbf{\Large\uppercase{Data analysis}}
\end{center}
\vfill
\phantom{*}
\newpage
\end{document}
答案1
由于您已经在使用 tikz 绘制边框,只需使用节点将文本放置在页面的中心(只是为了可视化,我在页面的中心添加了红点):
% !TeX TS-program = xelatex % | xelatex %
\documentclass[12pt, a4paper]{article}
\usepackage[left=3.3cm,right=2.3cm,top=2.3cm,bottom=2.3cm, footskip=42pt]{geometry}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw[line width=3pt] ($(current page.north west)+(2.5cm,-1.5cm)$) rectangle ($(current page.south east)+(-1.5cm,1.5cm)$);
\draw[line width=1pt] ($(current page.north west)+(2.6cm,-1.6cm)$) rectangle ($(current page.south east)+(-1.6cm,1.6cm)$);
\fill[red] (current page.center) circle (0.1);
\node[font=\Large\bfseries, text width=5cm,align=center] at (current page.center) {
\uppercase{Note -- 1}
\vspace{24pt}
\uppercase{Data analysis}
};
\end{tikzpicture}
\newpage
test
\end{document}
或者也许您希望它位于框架的中心而不是整个页面的中心?
% !TeX document-id = {a3867b77-1acb-4c22-aa49-faff0df3de47}
% !TeX TS-program = xelatex % | xelatex %
\documentclass[12pt, a4paper]{article}
\usepackage[left=3.3cm,right=2.3cm,top=2.3cm,bottom=2.3cm, footskip=42pt]{geometry}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\coordinate (A) at ($(current page.north west)+(2.5cm,-1.5cm)$) ;
\coordinate (B) at ($(current page.south east)+(-1.5cm,1.5cm)$) ;
\draw[line width=3pt] (A) rectangle (B);
\draw[line width=1pt] ($(A)+(0.1cm,-0.1cm)$) rectangle ($(B)+(-0.1cm,0.1cm)$);
\node[font=\Large\bfseries, text width=5cm,align=center] at ($(A)!0.5!(B)$) {
\uppercase{Note -- 1}
\vspace{24pt}
\uppercase{Data analysis}
};
\end{tikzpicture}
\newpage
test
\end{document}