2

From this question How to get the height of a minipage to set the height of another one? I found useful the answer of @egreg. Is there a way

  1. the first column to be aligned at the top?
  2. the tikzpicture to be set in the center in relation to the first column?
\documentclass[a4paper,11pt]{article}

\usepackage{enumitem} \usepackage{tikz}

\begin{document}

\begin{enumerate} \item \valign{#\cr \hsize=0.49\linewidth Text\newline Text\newline Text\newline Text\newline \cr \noalign{\hfill} \hsize=0.49\linewidth \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture} \cr } \item \valign{#\cr \hsize=0.49\linewidth Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline \cr \noalign{\hfill} \hsize=0.49\linewidth \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture} \cr } \end{enumerate}

\end{document}

enter image description here

Fotis K
  • 195
  • Why don't you use two minipages and align them using the [c] alignment? – Skillmon Nov 17 '20 at 13:19
  • I like this way and I want to learn more about the command \valign. Also, I tried with two minipages but didn't work as I would prefer. – Fotis K Nov 17 '20 at 13:37
  • Well, it isn't vertically centred as you didn't put a \vfill above and below the contents of the two columns (that's the easy part). – Skillmon Nov 17 '20 at 15:52

2 Answers2

1

The following aligns the numbers with the first line of the left column while the two columns are vertically centred to each other. It does so by first typesetting the left column with the alignment on the baseline of the first row via \vtop inside a box. Then the \valign is moved via \raisebox. -\height will move the contents completely below the baseline, and \dp\valignalign@box will move it up so that the baseline is on the same point as it would for the \vtop alone.

To vertically centre the two columns to each other I use \vfil#\vfil\cr for the \valign preamble. Since basically the same code is used two times, I put it into a macro.

\documentclass[a4paper,11pt]{article}

\usepackage{enumitem} \usepackage{tikz}

\makeatletter \newsavebox\valignalign@box \newcommand\valignalign[4] {% \setbox\valignalign@box\vtop{\hsize=#1\linewidth#2\par}% \raisebox{\dimexpr-\height+\dp\valignalign@box\relax}{% \valign{\vfil##\vfil\cr \hsize=#1\linewidth \unvbox\valignalign@box \cr \noalign{\hfil}% \hsize=#3\linewidth #4% \cr }}% } \makeatother

\begin{document}

\begin{enumerate} \item \valignalign {.49} {% Text\newline Text\newline Text\newline Text\newline } {.49} {% \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture}% }% \item \valignalign {.49} {% Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline Text\newline } {.49} {% \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture}% }% \end{enumerate}

\end{document}

enter image description here

Skillmon
  • 60,462
0

You can use adjustbox:

\documentclass[a4paper,11pt]{article}

\usepackage{enumitem} \usepackage{adjustbox} \usepackage{tikz}

\usepackage{lipsum} % for mock text

\begin{document}

\begin{enumerate} \item \adjustbox{valign=t}{\valign{#\cr \hsize=0.49\linewidth \lipsum[4][1-2] \cr \noalign{\hfill} \hsize=0.49\linewidth \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture} \cr }} \item \adjustbox{valign=t}{\valign{#\cr \hsize=0.49\linewidth \lipsum[4][1-2] \lipsum[4][1-2] \lipsum[4][1-2] \lipsum[4][1-2] \lipsum[4][1-2] \lipsum[4][1-2] \cr \noalign{\hfill} \hsize=0.49\linewidth \centering \begin{tikzpicture} \draw[->] (-0.75,0) -- (pi,0) node[below] {$x$}; \draw[->] (0,-0.5) -- (0,2) node[left] {$y$}; \fill (0,0) circle[radius=0.025] node[below left] {$O$}; \end{tikzpicture} \cr }} \end{enumerate}

\end{document}

enter image description here

egreg
  • 1,121,712