将小页面中的文本沿页面中心居中

将小页面中的文本沿页面中心居中

对于单页公告,我需要在页面末尾添加一些文字和徽标。到目前为止,我使用 minipages 获得了初步成果:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{tikz}

\begin{document}

\noindent
\begin{minipage}{0.8\textwidth}
 \begin{center}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
Curabitur dictum gravida mauris. Nam arcu libero, nonummy
eget, consectetuer id, vulputate a, magna. Donec vehicula
augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo.
\end{center}
\end{minipage}
\hfill
\begin{minipage}{4.5\baselineskip}
\begin{tikzpicture}[scale=2]
 \path[draw] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{minipage}
\end{document}

但是,文本沿小页面中心居中,而不是原始页面中心居中。有没有什么方法可以解决这个问题,例如使用 centering 的可选参数?

答案1

我猜你想测量 TikZ 图片的宽度,添加一些填充(这里与列之间使用的相同tabular):

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{showframe}

\newsavebox{\finallogobox}
\newlength{\finallogowd}

\newcommand{\finallogo}{%
  \sbox{\finallogobox}{%
    \begin{tikzpicture}[scale=2]
    \path[draw] (0,0) rectangle (1,1);
    \end{tikzpicture}%
  }%
  \setlength{\finallogowd}{\textwidth}%
  \addtolength{\finallogowd}{-2\wd\finallogobox}%
  \addtolength{\finallogowd}{-4\tabcolsep}%
  \noindent
  \phantom{\usebox{\finallogobox}}%
  \hfill
  \begin{minipage}{\finallogowd}
    \centering
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
    purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
    Curabitur dictum gravida mauris. Nam arcu libero, nonummy
    eget, consectetuer id, vulputate a, magna. Donec vehicula
    augue eu neque. Pellentesque habitant morbi tristique senectus
    et netus et malesuada fames ac turpis egestas. Mauris ut leo.
  \end{minipage}%
  \hfill
  \begin{tabular}{@{}c@{}}
  \usebox{\finallogobox}
  \end{tabular}\par
}


\begin{document}

\finallogo

\end{document}

showframe包仅用于清晰地查看最终效果。tabular图片周围的部分用于相对于文本垂直居中。

在此处输入图片描述

答案2

我仅使用一张图片就找到了解决方案TikZ。我使用了一些来自零的代码,请参阅这里

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{tikz}

% Defining a new coordinate system for the page:
%
% --------------------------
% |(-1,1)    (0,1)    (1,1)|
% |                        |
% |(-1,0)    (0,0)    (1,0)|
% |                        |
% |(-1,-1)   (0,-1)  (1,-1)|
% --------------------------
\makeatletter
\def\parsecomma#1,#2\endparsecomma{\def\page@x{#1}\def\page@y{#2}}
\tikzdeclarecoordinatesystem{page}{
    \parsecomma#1\endparsecomma
    \pgfpointanchor{current page}{north east}
    % Save the upper right corner
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    % save the lower left corner
    \pgfpointanchor{current page}{south west}
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    % Transform to the correct placement
    \pgfmathparse{(\pgf@xc-\pgf@xb)/2.*\page@x+(\pgf@xc+\pgf@xb)/2.}
    \expandafter\pgf@x\expandafter=\pgfmathresult pt
    \pgfmathparse{(\pgf@yc-\pgf@yb)/2.*\page@y+(\pgf@yc+\pgf@yb)/2.}
    \expandafter\pgf@y\expandafter=\pgfmathresult pt
}
\makeatother

\begin{document}

\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\node[draw,text width=.6\paperwidth] at (current page.center) {
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo.};
\draw[thick] (page cs:-.2,-.8) rectangle (page cs:.2,-.6);
\end{tikzpicture}
\end{document}

产生以下内容输出

相关内容