4

Consider the example below. Why is the text not vertically centered?

How do I get this working? I want to get this working with a node assigned to a draw object, because else I need to modify my entire figure ;-)

Credits for the fitting node goes to this post.

enter image description here

MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\makeatletter
\tikzset{
  fitting node/.style={
    inner sep=0pt,
    fill=none,
    draw=none,
    reset transform,
    fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
  },
  reset transform/.code={\pgftransformreset}
}
\makeatother
\begin{document}
\begin{tikzpicture}[ultra thick]
  \draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0) node[fitting node] {\strut Test Title};
\end{tikzpicture}
\end{document}
2

enter image description here

nodes with fit option doesn't center the content (top images), so with your solution you can achieve this using label (middle image) or use standard node (bottom image):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\makeatletter
\tikzset{
  fitting node/.style={
    inner sep=0pt,
    fill=none,
    draw=none,
    reset transform,
    fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
  },
  reset transform/.code={\pgftransformreset}
}
\makeatother
\begin{document}
\begin{tikzpicture}[ultra thick]
  \draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0) node[fitting node] {Test Title};
\end{tikzpicture}

\bigskip
\begin{tikzpicture}[ultra thick]
  \draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0) 
        node[fitting node, label=center: Test Title]{};
\end{tikzpicture}

\bigskip
    \begin{tikzpicture}[
titlebox/.style args = {#1/#2}{%
        draw, rounded corners=15pt, ultra thick,
        text width=#1, minimum height=#2, align=center}
                ]
\node[titlebox=135mm/10mm] {Test Title};
\end{tikzpicture}

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.