# Centering is not working in a minipage

I've seen this answer: Centering is not working, but my problem is not centering a tabular environment.

I want to center the second line in a two line minipage.

• The contents of the minipage are given by a definition.
• The text is a constant width, hence the need for a minipage.
• The definition is needed because the text changes through iterations.
• The \begin{center} ... \end{center} environment is not desirable because of the added vertical space.
• align=left as an argument on \node is necessary to left align the first line. However, removing this does not change the alignment of either line in the definition.

Where I'm now putting \centering in not achieving the desired result.

How can I get the second line centered while left-aligning the first line, given the current constraints/conditions?

I'm working with the following MWE:

\documentclass[]{article}

\usepackage{tikz}
\usepackage{setspace}
\usetikzlibrary{positioning}

\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}[x=1.0cm, y=1.0cm]

\node[circle, draw=red] (aa) at (0,0) {};
\def\myreference{References: \\ {\centering Kim, et. al., May 2019 } }
\node[align=left, draw=black,
xscale=1.0, yscale=1.0,
rounded corners=1.5ex,
inner xsep=0.150cm,
above = 0.00cm of aa
] (reference) {\begin{minipage}{0.50\textwidth} \setstretch{0.5} { \tiny \myreference }\end{minipage} };

\end{tikzpicture}
\end{center}

\end{document}


## 2 Answers

You're almost there; you just need to add \raggedright and \\.

\documentclass[]{article}

\usepackage{tikz}
\usepackage{setspace}
\usetikzlibrary{positioning}

\begin{document}
\thispagestyle{empty}

\begin{center}
\begin{tikzpicture}[x=1.0cm, y=1.0cm]
\node[circle, draw=red] (aa) at (0,0) {};
\def\myreference{References: \\ {\centering Kim, et. al., May 2019 \\ } }
\node[
align=left,
draw=black,
xscale=1.0,
yscale=1.0,
rounded corners=1.5ex,
inner xsep=0.150cm,
above = 0.00cm of aa,
] (reference) {%
\begin{minipage}{0.50\textwidth}
\setstretch{0.5}\tiny\raggedright
\myreference
\end{minipage}%
};

\end{tikzpicture}
\end{center}

\end{document}


Something like this?

\documentclass[]{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}[x=1.0cm, y=1.0cm]

\node[circle, draw=red] (aa) at (0,0) {};
\def\myreference{References: \\\hfill Kim, et. al., May 2019\hfill\mbox{}}
\node[align=left, draw=black,
xscale=1.0, yscale=1.0,
rounded corners=1.5ex,
inner xsep=0.150cm,
above = 0.00cm of aa,
text width=0.5\textwidth,
font=\tiny
] (reference) {\myreference};

\end{tikzpicture}
\end{center}

\end{document}


• I liked your answer since it met my objectives, but I found the answer that preserved the minipage to be more aligned with my goals. Thanks! – David Collins Feb 24 at 13:19
• @DavidCollins That's fine, of course. Note, however, that using \tiny as in the accepted answer is wrong. It has to be set with font=\tiny. – Schrödinger's cat Feb 24 at 14:53