3

I would like to put a tikzpicture and an align environment side by side within a figure using minipages. However they are not at the same height. Here is my example code

\documentclass[11pt,leqno]{scrreprt} 
\usepackage{amsmath}    
\usepackage{tikz}

\begin{document}

\begin{figure}[h] 
    \begin{minipage}[t]{.2\linewidth}
    \centering
    \begin{tikzpicture}[trop/.style={very thick},scale=0.35]
    \draw[gray!40!] (-0.5,-0.5) grid (15.5,15.5);
    \draw[->,thick] (-.5,0)--(14.5,0);
    \draw[->,thick] (0,-.5)--(0,14.5);
    \end{tikzpicture}
    \end{minipage}
      \hfill
    \begin{minipage}[t]{.2\linewidth} %inequalities
    \centering
    \begin{align*}
    &\text{1} & \max\{x_1,2\}   &\le 2+x_2\\
    &\text{2} & x_1         &\le \max\{2+x_2,4\}\\
    &\text{3} & x_1         &\le    \max\{-2+x_2,2\}\\
    &\text{4} & \max\{x_1,-1+x_2\}&\le 2
    \end{align*}
    \end{minipage}
\end{figure}

\end{document}

Thanks in advance.

3 Answers 3

3

Just change the [t] in front of the minipage into [c]:

\documentclass[11pt,leqno]{scrreprt} 
\usepackage{amsmath}    
\usepackage{tikz}

\begin{document}

\begin{figure}[h] 
    \begin{minipage}[c]{.2\linewidth}
    \centering
    \begin{tikzpicture}[trop/.style={very thick},scale=0.35]
    \draw[gray!40!] (-0.5,-0.5) grid (15.5,15.5);
    \draw[->,thick] (-.5,0)--(14.5,0);
    \draw[->,thick] (0,-.5)--(0,14.5);
    \end{tikzpicture}
    \end{minipage}
      \hfill
    \begin{minipage}[c]{.2\linewidth} %inequalities
    \centering
    \begin{align*}
    &\text{1} & \max\{x_1,2\}   &\le 2+x_2\\
    &\text{2} & x_1         &\le \max\{2+x_2,4\}\\
    &\text{3} & x_1         &\le    \max\{-2+x_2,2\}\\
    &\text{4} & \max\{x_1,-1+x_2\}&\le 2
    \end{align*}
    \end{minipage}
\end{figure}

\end{document}
1
  • Why .2\linewidth ? It should be .49\linewidth .
    – Black Mild
    Sep 4, 2019 at 19:14
2

Set the baseline of the picture to the center:

\documentclass[11pt,leqno]{scrreprt}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}

\begin{figure}[htp]
\centering

\begin{tikzpicture}[trop/.style={very thick},scale=0.35,baseline=(current bounding box.center)]
  \draw[gray!40!] (-0.5,-0.5) grid (15.5,15.5);
  \draw[->,thick] (-.5,0)--(14.5,0);
  \draw[->,thick] (0,-.5)--(0,14.5);
\end{tikzpicture}\hfill
$\begin{aligned}
  &\text{1} & \max\{x_1,2\}   &\le 2+x_2\\
  &\text{2} & x_1         &\le \max\{2+x_2,4\}\\
  &\text{3} & x_1         &\le    \max\{-2+x_2,2\}\\
  &\text{4} & \max\{x_1,-1+x_2\}&\le 2
\end{aligned}$

\end{figure}

\end{document}

enter image description here

2

You don't really need minipages (your code results in \overfull\hbox messages. A simple \adjustbox{valign=c} for the tikz picture, and the aligned environment will do. I also suggest another alignment for the equations:

\documentclass[11pt,leqno]{scrreprt}
\usepackage[showframe]{geometry}
\usepackage{adjustbox}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}

\begin{figure}[h]
 \hfill        
    \adjustbox{valign=c}{\begin{tikzpicture}[trop/.style={very thick},scale=0.35]
    \draw[gray!40!] (-0.5,-0.5) grid (15.5,15.5);
    \draw[->,thick] (-.5,0)--(14.5,0);
    \draw[->,thick] (0,-.5)--(0,14.5);
    \end{tikzpicture}}
      \hfill
    $ \begin{aligned}
    &\text{1} & & \max\{x_1,2\} \le 2+x_2\\
    &\text{2} & & x_1\le \max\{2+x_2,4\}\\
    &\text{3} & & x_1\le \max\{-2+x_2,2\}\\
    &\text{4} & & \max\{x_1,-1+x_2\}\le 2
    \end{aligned} $
    \hfill\null
\end{figure}

\end{document}

enter image description here

2
  • I get the following error: Undefinded control sequence. \adjustbox
    – mabu
    Apr 6, 2018 at 11:01
  • 1
    @mabu: Sorry, I didn't check I forgot to load the adjustbox package (an extension of graphicx) in the code. I've fixed it.
    – Bernard
    Apr 6, 2018 at 11:06

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.