# How to center a block of the lines while flushleft/flushright is applied

Obviously the following does not do what I have described in the title.

\documentclass{article}

\begin{document}

\begin{flushright}
\begin{center}
\vspace{1cm}
Here is the first line.\\
Second line.
\end{center}
\end{flushright}
\end{document}


In other words, I would like an output like this:

• It's not very clear: you want a centred block, but each line inside the block has to be flushright? – Bernard Jan 9 '17 at 10:19
• @Bernard I updated the question. – Name Jan 9 '17 at 10:29

You can use tabular often addresses in frontmatter are set this way.

\documentclass{article}

\begin{document}

\begin{center}
\begin{tabular}{@{}l@{}}
Here is the first line.\\
Second line.
\end{tabular}
\end{center}
\begin{flushright}
\begin{tabular}{@{}c@{}}
Here is the first line.\\
Second line.
\end{tabular}
\end{flushright}
\end{document}


Maybe you expect a right aligned block of centred lines. If so, you could use varwidth:

\documentclass{article}
\usepackage{varwidth}
\begin{document}

\begin{flushright}
\begin{varwidth}{\linewidth}\centering
Here is the first line.\\
Second line.
\end{varwidth}
\end{flushright}
\end{document}


• That's a bit of overkill: since you're specifying the line breaks, a tabular is easier. – egreg Jan 9 '17 at 10:33
• @egreg: As long as you really have only manually specified line breaks and as long as it doesn't matter that every line is a group on its own and as long a you have not changed e.g. line stretching of tabular rows in the document preamble. Sometimes pretended overkill may become a prefered solution. – Schweinebacke Jan 9 '17 at 10:53
• I didn't mean the solution is bad! To the contrary, I upvoted it. – egreg Jan 9 '17 at 11:24