Tikz – Box/frame arround Text with interruption

Something like this? The vertical distances are controlled by inner ysep, and the horizontal ones by inner xsep.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[font=\sffamily\bfseries]
 \node[scale=4,red!60,inner xsep=1.5ex,inner ysep=0.5ex] (2019){2019};
 \node[above,scale=2,gray!50] at (2019.north) (A) {Name xy};
 \node[below,scale=2,gray!50] at (2019.south) (B) {Name};
 \draw[thick,gray!50] (A.east) -| (2019.east|-B) -- (B.east)
 (A.west) -| (2019.west|-B) -- (B.west);
\end{tikzpicture}
\end{document}

enter image description here


Just for fun a TikZ-less version, that only uses xcolor and grabbox (grabbox wouldn't really be necessary, but this way you can use \verb and stuff in the braced arguments).

Argument structure of \boxtext is:

  • optional argument specifying fixed width of top-text
  • mandatory argument for top-text
  • optional argument specifying fixed width of main-text
  • mandatory argument for main-text
  • optional argument specifying fixed width of bottom-text
  • mandatory argument for bottom-text

If you don't specify a fixed width the natural width is used, if a fixed width is specified the contents will be centred using \centering.

\documentclass[]{article}

\usepackage{xcolor}
\usepackage{grabbox}

\makeatletter
\colorlet{boxtextborder}{gray}
\newlength\toptextpad
\newlength\maintextpad
\newlength\bottomtextpad
\newlength\boxtextborder
\setlength\toptextpad{2pt}
\setlength\maintextpad{5pt}
\setlength\bottomtextpad{2pt}
\setlength\boxtextborder{.4pt}
\newlength\[email protected]
\newsavebox\[email protected]
\newsavebox\[email protected]
\newsavebox\[email protected]
\def\[email protected]\fi#1#2#3{\fi#2}
\newcommand\[email protected][1]
  {%
    \ifx\relax#1%
      \[email protected]
    \fi
    \@secondoftwo
  }
\newcommand\boxtext[1][\relax]
  {%
    \[email protected]{#1}
      {\@grabbox{}\[email protected]{\color{boxtextborder}}\hbox}
      {\@grabbox{\hsize#1\centering}\[email protected]{\color{boxtextborder}}\vbox}%
    {}\[email protected]
  }
\newcommand\[email protected][1][\relax]
  {%
    \[email protected]{#1}
      {\@grabbox{}\[email protected]{}\hbox}
      {\@grabbox{\hsize#1\centering}\[email protected]{}\vbox}%
    {}\[email protected]
  }
\newcommand\[email protected][1][\relax]
  {%
    \[email protected]{#1}
      {\@grabbox{}\[email protected]{\color{boxtextborder}}\hbox}
      {\@grabbox{\hsize#1\centering}\[email protected]{\color{boxtextborder}}\vbox}%
    {}\[email protected]
  }
\newcommand*\[email protected]
  {%
    \vrule
      height
        \dimexpr
          \ht\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\toptextpad+\maintextpad+.5\boxtextborder
        \relax
      depth
        \dimexpr
          \dp\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\maintextpad+\bottomtextpad+.5\boxtextborder
        \relax
      width \boxtextborder
    \relax
  }
\newcommand*\[email protected]
  {%
    \vrule
      width
        \dimexpr
          (\[email protected]\wd\[email protected])/2-\toptextpad
        \relax
      height
        \dimexpr
          \ht\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\toptextpad+\maintextpad+.5\boxtextborder
        \relax
      depth
        -\dimexpr
          \ht\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\toptextpad+\maintextpad-.5\boxtextborder
        \relax
    \relax
  }
\newcommand*\[email protected]
  {%
    \vrule
      width
        \dimexpr
          (\[email protected]\wd\[email protected])/2-\bottomtextpad
        \relax
      height
        -\dimexpr
          \dp\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\maintextpad+\bottomtextpad-.5\boxtextborder
        \relax
      depth
        \dimexpr
          \dp\[email protected]+.5\ht\[email protected]+.5\dp\[email protected]
          +\maintextpad+\bottomtextpad+.5\boxtextborder
        \relax
    \relax
  }
\newcommand*\[email protected]
  {%
    \mbox
      {%
        \begingroup
        \ifdim\wd\[email protected]>\wd\[email protected]
          \ifdim\wd\[email protected]>\wd\[email protected]
            \[email protected]\wd\[email protected]
          \else
            \[email protected]\wd\[email protected]
          \fi
        \else
          \ifdim\wd\[email protected]>\wd\[email protected]
            \[email protected]\wd\[email protected]
          \else
            \[email protected]\wd\[email protected]
          \fi
        \fi
        \advance\[email protected]\maintextpad
        \color{boxtextborder}%
        \[email protected]
        \rlap{\makebox[\[email protected]][c]{\usebox\[email protected]}}%
        \rlap
          {%
            \makebox[\[email protected]][c]
              {%
                \raisebox
                  {%
                    \dimexpr
                      \ht\[email protected]+\dp\[email protected]
                      +\maintextpad+\toptextpad
                  }
                  {\usebox\[email protected]}%
              }%
          }%
        \rlap
          {%
            \makebox[\[email protected]][c]
              {%
                \raisebox
                  {%
                    -\dimexpr
                      \dp\[email protected]+\ht\[email protected]
                      +\maintextpad+\bottomtextpad
                  }
                  {\usebox\[email protected]}%
              }%
          }%
        \rlap{\[email protected]}%
        \rlap{\[email protected]}%
        \hskip\[email protected]
        \llap{\[email protected]}%
        \llap{\[email protected]}%
        \[email protected]
        \endgroup
      }%
  }
\makeatother

\begin{document}
\boxtext
  {Name xy}
  {\textcolor{red}{2019}}
  {Name}%

\boxtext
  {\textsf{Name xy}}
  {{\sffamily\bfseries\huge\textcolor{red}{2019}}}
  {\textsf{Name}}

\boxtext{Name xy}[5cm]{This is some text that is 5cm wide}{Name}
\end{document}

enter image description here

Tags:

Box

Tikz Pgf