1

to make it clear, I would like to reproduce this:

in a way that the lines automatically fill the space on the right and left of the word in the center (as I need to use it for several titles).

Thank you very much!

2
  • 1
    Are you OK about using TikZ to do this?
    – SebGlav
    Commented Feb 24, 2022 at 20:33
  • Yes no problem with TikZ, thank you! Commented Feb 24, 2022 at 21:49

2 Answers 2

2

Your question is not very clear. I assume, that wide of this line is \textwidth, so it is something like this?

enter image description here

Edit:

  • For compensating ident should be before image code in document added command \noindent.

  • in definition of command to draw this image the \noindent is part of image code, so a care of positioning of suit command is not needed anymore.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\noindent\tikz\draw[line width=1.2ex, shorten >=1.2ex, line cap=round, gray] 
        (0,0) -- node[fill=white] {Suites}  (\linewidth,0);
\end{document}

or this:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}
\noindent\tikz{\path (0,0) -- node[inner xsep=1em] (s) {Suites} ++ (\linewidth,0);
      \draw[line width=1.2ex, line cap=round, gray]  (0,0) -- (s);
      \draw[line width=1.2ex, shorten >=1.2ex, line cap=round, gray]  (s) -- (\linewidth,0);
      }
\end{document}

Edit: If you need it more than once, than defining new command can be handy:

\documentclass{article}
\usepackage{tikz}

\NewDocumentCommand\suit{m}{\par\noindent%
\tikz{\path (0,0) -- node[inner xsep=1em] (s) {#1} (\linewidth,0);
      \draw[line width=1.2ex, line cap=round, gray]  (0,0) -- (s);
      \draw[line width=1.2ex, shorten >=1.2ex, line cap=round, gray]  (s) -- (\linewidth,0);
      }}
\begin{document}
\suit{SUITE}
\end{document}

Result of compilation is the same as before. This command can be used also in boxes. For example:

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\NewDocumentCommand\suit{m}{\par\noindent%
\tikz{\path (0,0) -- node[inner xsep=1em] (s) {#1} (\linewidth,0);
      \draw[line width=1.2ex, line cap=round, gray]  (0,0) -- (s);
      \draw[line width=1.2ex, shorten >=1.2ex, line cap=round, gray]  (s) -- (\linewidth,0);
      }}
\begin{document}
\lipsum[11]\par
\hfil\fbox{%
  \parbox{0.8\textwidth}{
\suit{Start}
\lipsum[66]
\suit{The end}
    }}
\end{document}

gives:

enter image description here

2
  • Thank you so much, this is perfect! Commented Feb 25, 2022 at 14:07
  • @stargazer45, see edited answer. Added ar \noindent in examples as well in definition of the command \suite .
    – Zarko
    Commented Feb 25, 2022 at 15:39
0

Zarko's answer is much more elegant than mine but since I had already been working on it I present it here as a secondary solution. (I also get Overful \hbox too wide when running Zarko's code, probably because of this).

\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\newcommand{\splitheading}[1]{
\setbox0=\hbox{#1}
\noindent
\begin{tikzpicture}[
txt/.style={red,draw=none, fill=none},
line/.style={draw=none, fill=none,inner sep=0}]
\node(mid)[txt]{#1};
\node(first)[line,left = ((\textwidth-\the\wd0)/2)-6 of mid]{};
\node(second)[line,right = ((\textwidth-\the\wd0)/2)-6 of mid]{};
\path[Round Cap-Round Cap,red,line width=1ex](first)edge(mid)(mid)edge(second);
\end{tikzpicture}}

\splitheading{Suites}

This is the result compared: enter image description here

1
  • Thank you so much, that was useful! Commented Feb 25, 2022 at 19:05

You must log in to answer this question.

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