[Tex/LaTex] Node in TikZ : change text alignment in one node

horizontal alignmenttikz-pgf

I am working with tikz, and I am wondering if there is a simple way to have different text aligment in one node ?

For instance, in my MWE below, I would like to have blabla1 centered, but blabla2 and blabla3 left aligned. For now I have tried to set left align by default, and to use \centering on blabla1; but it also centers blabla2 (but not the third one…)

How to fix that and is there a better way ?

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz-cd}
\usepackage{lscape}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,shapes}

\begin{document
\tikzstyle{block4} = [rectangle, draw, fill=blue!20, text width=6cm, rounded corners, minimum height=4em]

\begin{tikzpicture}[node distance = 2cm, auto]
\centering
% Place nodes
\node [block4] (Foyer) 
                        {\centering{\emph{blabla1} }
                        \\ blabla2
                        \\ blabla3};

\end{tikzpicture}
\end{document}

Best Answer

In general, use styles for nodes.

If you have a line with different alignment or different font size, end the line or the paragraph before the alignment or style is changed, i.e. \\ should be inside, before the closing brace, here.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto,
  block4/.style = {rectangle, draw, fill=blue!20, text width=6cm,
                   rounded corners, minimum height=4em}]
  \node [block4] (Foyer) { {\centering \emph{line1} \\ }
                           line2 \\
                           line3};
\end{tikzpicture}
\end{document}