[Tex/LaTex] Center text in minipage along page center

horizontal alignmentminipage

For a one-page bulletin, I need some text and a logo on the end of a page. I've gotten first results with using minipages so far:

\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}

However, the text is centered along the minipage center, not the original page center. Is there some way to circumvent this, for example with an optional argument to centering?

Best Answer

I guess you want to measure what's the width of the TikZ picture, add some padding (here the same used between columns in 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}

The showframe package is used only to clearly see the final effect. The tabular around the picture is for vertically centering it with respect to the text.

enter image description here

Related Question