Draw horizontal line vertically centralized

The xhfill package provides tools to customise \hrulefill:

\documentclass[svgnames]{article}
\usepackage{xhfill}
\usepackage{lipsum}

\begin{document}

\textbf{Work Experience} \xrfill[0.5ex]{0.6pt}[Crimson]
\medskip

\lipsum{1}

\end{document}  

enter image description here


Here are two ways of accomplishing your goal:

  • \raisebox{0.5ex}{<code for horizontal rule>}

  • $\vcenter{\hbox{<code for horizontal rule>}}$

The former raises the rule by 0.5ex, where ex is the font's so-called x-height. The latter places the rule centered on the math axis. (In case you're wondering where the math-axis is located: In math mode, the - (minus) symbol is placed on the math axis, while the = symbol is centered vertically on it.)

The output of the two methods is fairly similar as long as the horizontal rule isn't too thick. In the following screenshot, the length and width of the rules is set to 6em and 0.4pt, respectively. You're obviously free to choose other values.

enter image description here

\documentclass{article}
\begin{document}
\textbf{Experience} \raisebox{0.5ex}{\rule{6em}{0.4pt}} $\vcenter{\hbox{\rule{6em}{0.4pt}}}$
\end{document}

Following an answer to my past question

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
    Work Experience $\vcenter{\hbox{\begin{tikzpicture}\draw[-]  (0,0) -- ++(10mm,0);\end{tikzpicture}}}$
\end{document}

Tags:

Pdftex