33

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).

39

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}

enter image description here

2

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.

Example

Example

Code

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

\begin{document}
The original one 
\frame{
\begin{tikzpicture}
    \begin{axis}[width=10 ex, height = 3 ex, 
                 scale only axis, hide axis]
        \addplot[black] {rand};
    \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]
        \addplot[black] {rand};
    \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]
        \addplot[black] {rand};
    \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,
    ]
    \addplot[black] {rand};
    \end{axis};
\end{tikzpicture}}}
does work in this case, but I don't know why.
\end{document}
  • 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. – percusse Sep 8 '16 at 16:32
  • @percusse Sorry I'm not sure what you mean. You mean you can also push them in a positive direction? I've tried that, but that does nothing. – Roald Sep 9 '16 at 16:23

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.