# Inline TikZ - vertical centering

If I inline a bounded line segment like this:

the distance \tikz{ \draw [|-|] (0,0) -- (5ex,0); } overarching the activities


how can I make the line appear vertically centered on the line (automatically taking into account the line height).

You can directly tell where the baseline should meet the picture using the baseline option

\documentclass{article}
\usepackage{tikz}
\begin{document}
the distance \tikz[baseline=-0.5ex]{ \draw [|-|] (0,0) -- (5ex,0); } overarching the activities
\end{document}


Neither percusse's nor Claudio's answer worked for me when I wanted to insert a small inline graph. Instead Martin's suggestion of \raisebox did work.

## Code

\documentclass{article}
\usepackage{pgfplots} %for drawing of graphs
\setlength{\parindent}{0pt}

\begin{document}
The original one
\frame{
\begin{tikzpicture}
\begin{axis}[width=10 ex, height = 3 ex,
scale only axis, hide axis]
\end{axis};
\end{tikzpicture}}
is too high.

And percusse's \verb|[baseline=-0.5 ex]|
\frame{
\begin{tikzpicture}[baseline=-0.5ex]
\begin{axis}[width=10 ex, height = 3 ex,
scale only axis, hide axis]
\end{axis};
\end{tikzpicture}}
does not work, it only shifts
\frame{
\begin{tikzpicture}
\begin{axis}[width=10 ex, height = 3 ex,
scale only axis, hide axis]
\end{axis};
\end{tikzpicture}}
the graph upwards a little.

\verb|\raisebox{-.5 ex}|
\raisebox{-.5 ex}{\frame{
\begin{tikzpicture}
\begin{axis}[
width=10 ex, height = 3 ex, scale only axis,
hide axis,
]

• Because you are trying to push down -0.5ex adjust the baseline position for that example. As I commented, you can adjust with baseline to be wherever you want. Sep 8, 2016 at 16:32
• Question: is 3 ex the height that won't mess with the interline? Also, to answer your question, you wanted to push the baseline 1 ex down (positive value, not negative), not just 0.5 ex (you got the amount and sign wrong in your reply) since the total height is 3 ex and you want it centred at mid x's height, which is 0.5 ex. Sep 29, 2022 at 16:58