21

I'm trying to make a diagram using Tikz, however I have trouble combining; fixed text widths, centered text and font=[\large,\bf , etc].

When the font command is used the text has a slight offset to the right.

the only idea I had, font=\noindent has no effect. MWE:

\documentclass[a4paper,landscape]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,graphs}

\begin{document}
\centering
\begin{tikzpicture}
\thispagestyle{empty}
\tikzstyle{fontbf} = [draw,rectangle,text width=11em,text centered,font=\bf]
\tikzstyle{textbf} = [draw,rectangle,text width=11em,text centered]
\node[fontbf] (1) {centered bold text};
\node[textbf, below of=1] (2) {\textbf{centered bold text}};
\end{tikzpicture}
\end{document}
1

1 Answer 1

29

The problem is that you are using font specific units to set the text width (em) and these units are different for bold and non-bold text. Use cm instead and the problem will disappear.

\documentclass[a4paper,landscape]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,graphs}
\begin{document}
  \centering
  \begin{tikzpicture}
    \thispagestyle{empty}
    \tikzstyle{fontbf} = [draw,rectangle,text width=5cm,text centered,font=\bfseries]
    \tikzstyle{textbf} = [draw,rectangle,text width=5cm,text centered]
    \node[fontbf] (1) {centered bold text};
    \node[textbf, below of=1] (2) {\textbf{centered bold text}};
  \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .