7

There are a bunch of related questions here. But I was not yet able to pull this off yet.

I have the following code: (where hist.tex is a plot drawing)

\fbox{\scalebox{0.40} {\input{hist.tex}}}
\quad
\begin{tabular}{ll}
    p: 78\%&\\\\
    $\mu$: -7\% & $\sigma$: 7\%\\
    $\alpha$: 0.43 & N: 11977
\end{tabular}

The output:

shot
(source: fc.up.pt)

I would like them to be aligned!!

Ricardo Cruz
  • 1,770
  • 1
  • 22
  • 34
  • 1
    Use [b] position specifier for tabular: ---> \begin{tabular}[b]{ll} –  Aug 07 '13 at 06:25
  • Harish, thx, yours was the simpler solution .. would give you credit if you answered ! – Ricardo Cruz Aug 09 '13 at 02:10
  • Ricardo, It is OK. Glad it helped. :) –  Aug 09 '13 at 02:17
  • @HarishKumar, you should make your comment an answer. I think it's the simplest and thus the best. – JRN Jan 16 '15 at 04:15
  • @JoelReyesNoche Thanks for the comment but jubobs has already answered in detail. I think it is sufficient. Have a nice day :) –  Jan 16 '15 at 04:19
  • @RicardoCruz If you're still round, you can upload pictures to this site, then they become a permanent part of the question/answers here. Your link no longer works so anyone interested in this question cannot see your picture. – Geoff Pointer Sep 06 '17 at 22:47

3 Answers3

4

Whether you want both objects aligned at the top or at the bottom, you can use two minipage environments and apply the \vspace{0pt} trick to obtain the desired vertical alignment (a quirk of TeX/LaTeX).

See also Understanding minipages - aligning at top for more details.

Set the optional argument to both minipage environments to

  • t for top alignment,
  • b for bottom alignment.

Note: I've used tikzpicture environment as placeholder for your graph, as you didn't provide the code for that.

enter image description here

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{tikz}

\begin{document}

\begin{minipage}[t]{.5\textwidth}
\vspace{0pt}
\raggedleft
    \begin{tikzpicture}
        \filldraw[draw=red,fill=red!20] rectangle (3,3);
    \end{tikzpicture}
\vspace{0pt}
\end{minipage}
\begin{minipage}[t]{.5\textwidth}
\vspace{0pt}
\raggedright
    \begin{tabular}{ll}
            p: 78\%&\\\\
            $\mu$: -7\% & $\sigma$: 7\%\\
            $\alpha$: 0.43 & N: 11977
    \end{tabular}
\vspace{0pt}
\end{minipage}  

\end{document}
David Carlisle
  • 757,742
jub0bs
  • 58,916
  • Hi Jubobs. Sorry for not posting the entire code, but I was just looking for a hint, not the full answer. :) – Ricardo Cruz Aug 07 '13 at 14:25
  • Anyhow, why all the spacing around the figure and the table? http://www.alunos.dcc.fc.up.pt/~up200405927/trash/latex2.png

    (I just wanted to put a figure and a table, as the transition label of a markov chain. I want them to be as compat as possible, because those markov chains can get very large ..)

    – Ricardo Cruz Aug 07 '13 at 14:27
  • Why the \vspace{0pt}, you mean? It's a trick to get the desired output. See the link in my answer. You can get the graph and the table pretty tight if you apply the code above. Do you need even tighter than that? – jub0bs Aug 07 '13 at 15:04
  • No, no. I mean, if you look at the picture in my comment .. Why is there such a big space around the graph and the table ? That is supposed to be the label of a tikz path, but it's very distant from it .. – Ricardo Cruz Aug 07 '13 at 15:12
  • If you would like to look at the code .. http://www.alunos.dcc.fc.up.pt/~up200405927/trash/latex.zip .. The graph & table look very distance from the transition they are associated to. – Ricardo Cruz Aug 07 '13 at 15:15
  • Based on the code in the .png you link to, the width of your minipages is too large (half the text width!). – jub0bs Aug 07 '13 at 15:15
4

You can use the adjustbox package which does all the work without you setting any length. Just change the mock tikzpicture with your plot.

\documentclass{article}

\usepackage{tikz}
\usepackage{adjustbox}

\begin{document}

\section{Centered alignment}

\begin{adjustbox}{valign=c}
\begin{tikzpicture}
  \filldraw[draw=red,fill=red!20] rectangle (3,3);
\end{tikzpicture}
\end{adjustbox}
\begin{tabular}{ll}
  p: 78\%&\\[2ex]
  $\mu$: -7\% & $\sigma$: 7\%\\
  $\alpha$: 0.43 & N: 11977
\end{tabular}

\section{Top alignment}

\begin{adjustbox}{valign=t}
\begin{tikzpicture}
  \filldraw[draw=red,fill=red!20] rectangle (3,3);
\end{tikzpicture}
\end{adjustbox}
\begin{tabular}[t]{ll}
  p: 78\%&\\[2ex]
  $\mu$: -7\% & $\sigma$: 7\%\\
  $\alpha$: 0.43 & N: 11977
\end{tabular}

\section{Bottom alignment}

%\begin{adjustbox}{valign=b} % adjustbox not really needed
\begin{tikzpicture}
  \filldraw[draw=red,fill=red!20] rectangle (3,3);
\end{tikzpicture}
%\end{adjustbox}
\begin{tabular}[b]{ll}
  p: 78\%&\\[2ex]
  $\mu$: -7\% & $\sigma$: 7\%\\
  $\alpha$: 0.43 & N: 11977
\end{tabular}

\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
1

Depending on whether you wanted it top or center aligned (or bottom for that matter), you would add differing amounts of vertical movement to the image. For my example, moving the top of the image 2 and 3 \baselineskip of upward shift relative to the baseline was sufficient (i.e., negative below-baseline = upward relative to top of image). Your mileage may vary.

\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}
\parskip 1em
\begin{document}
\def\x{\fbox{\scalebox{0.40} {\rule{2in}{2in}}}}
\def\y{%
\begin{tabular}{ll}
    p: 78\%&\\
\\
    $\mu$: -7\% & $\sigma$: 7\%\\
    $\alpha$: 0.43 & N: 11977
\end{tabular}}
\belowbaseline[-2\baselineskip]{\x}\quad\y \par
\belowbaseline[-3\baselineskip]{\x}\quad\y
\end{document}

enter image description here

Note that, if you needed a "precise" top alignment, it can be achieved with

\belowbaseline[-\ht\strutbox]{\x}\quad\belowbaseline[-\ht\strutbox]{\y}
David Carlisle
  • 757,742