1

So I want to have text next to a graph, and my solution was creating a two celled table.

    \begin{center}
    \begin{tabular}{ c p{100pt} }
    \begin{tikzpicture}
        \draw[thin,gray!40] (0,0) grid (4,4);
            \draw[->](0,0)--(4,0) node[right]{$x$};
            \draw[->](0,0)--(0,4) node[above]{$y$};
            \draw[line  width=2pt ,red,-stealth](1,0)--(1,4);
    \end{tikzpicture}
    &  Blah blah blah blah $\boldsymbol{u}$.   \\

And when it comes out, the text lines up with the bottom of the picture, is there a way which I can "trick" the text into thinking that it should line up with the top of the picture.

  • Welcome to TeX SX! Could you post a complete compilable code? – Bernard Sep 4 '18 at 21:44
  • You can always set the baseline of the tizkpicture to something. Give e.g. the $y$ node a name and align it to it. \begin{tikzpicture}[baseline=(y.base)] \draw[thin,gray!40] (0,0) grid (4,4); \draw[->](0,0)--(4,0) node[right]{$x$}; \draw[->](0,0)--(0,4) node[above](y){$y$}; \draw[line width=2pt ,red,-stealth](1,0)--(1,4); \end{tikzpicture} – user121799 Sep 4 '18 at 21:46
2

Just spelling out my comment.

\documentclass{article}
\usepackage{tikz,amsmath,amssymb}
\begin{document}
\begin{center}
    \begin{tabular}{ c p{100pt} }
    \begin{tikzpicture}[baseline=(y.base)]
        \draw[thin,gray!40] (0,0) grid (4,4);
            \draw[->](0,0)--(4,0) node[right]{$x$};
            \draw[->](0,0)--(0,4) node[above](y){$y$};
            \draw[line  width=2pt ,red,-stealth](1,0)--(1,4);
    \end{tikzpicture}
    &  Blah blah blah blah $\boldsymbol{u}$.   \\
\end{tabular}
\end{center}
\end{document}

enter image description here

And yes, I also know one should not use the center environment, but I have no idea how the full document looks like so I kept it.

  • I'll be happy to remove my answer in favor of someone who also explains why one should not use center and so on. Of course, I am aware of the fact that one can use arbitrary shifts e.g. by saying [baseline=([yshift=-5pt]y.base)], or one could use minipages and so on. – user121799 Sep 4 '18 at 22:24
2

As an alternative to side by side minipages or tabular, you can use a tcolorbox with options sidebyside (places upper and lower boxes side by side) and empty (no tcolorbox is drawn). You decide the vertical alignment between parts with sidebyside align (center by default).

\documentclass{article}
\usepackage{tikz,amsmath,amssymb}
\usepackage[most]{tcolorbox}

\begin{document}
\begin{tcolorbox}[sidebyside, empty]
    \begin{tikzpicture}[baseline=(y.base)]
        \draw[thin,gray!40] (0,0) grid (4,4);
            \draw[->](0,0)--(4,0) node[right]{$x$};
            \draw[->](0,0)--(0,4) node[above](y){$y$};
            \draw[line  width=2pt ,red,-stealth](1,0)--(1,4);
    \end{tikzpicture}
\tcblower
Blah blah blah blah $\boldsymbol{u}$.  
\end{tcolorbox}

\begin{tcolorbox}[sidebyside, empty, sidebyside align=top]
    \begin{tikzpicture}[baseline=(y.base)]
        \draw[thin,gray!40] (0,0) grid (4,4);
            \draw[->](0,0)--(4,0) node[right]{$x$};
            \draw[->](0,0)--(0,4) node[above](y){$y$};
            \draw[line  width=2pt ,red,-stealth](1,0)--(1,4);
    \end{tikzpicture}
\tcblower
Blah blah blah blah $\boldsymbol{u}$.  
\end{tcolorbox}

\end{document}

enter image description here

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.