3

Using the answers from this sight, I tried to accomplish top-aligned text and image where text would have to start from the left side of the page, and picture would be at the right side. However, using any method of stretching the table to the page width resulted in top alignment not working (tabularx or tabular* equally).

How can I keep the picture right-aligned and text top-aligned with picture at the same time?

\documentclass[border=10pt]{standalone}
\usepackage{pst-barcode}
\usepackage[crop=off]{auto-pst-pdf}

\begin{document}

\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} r}
\vspace{0pt}Title Text &
\vspace{0pt}
\begin{pspicture}(0.7in,0.7in)
    \psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{tabular*}

\end{document}

It did top-align text and picture when tabular was defined as follows:

\begin{tabular}{p{0.8\textwidth} p{0.8in}}
\vspace{0pt}Title Text &
\vspace{0pt}
\begin{pspicture}(0.7in,0.7in)
    \psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{tabular}
2
  • 1
    \vspace has no effect in a cell in an r column.
    – egreg
    Jun 20, 2014 at 15:19
  • I guess it does not, but the question remains.
    – ajeh
    Jun 20, 2014 at 15:20

1 Answer 1

3

\vspace{0pt} works in a p column because it's set in a \parbox. For an r column you can use adjustbox:

\documentclass{article}
\usepackage{adjustbox}
\usepackage{pst-barcode}
\usepackage[crop=off]{auto-pst-pdf}

\begin{document}

\begin{tabular*}{\textwidth}{@{}l @{\extracolsep{\fill}} r@{}}
Title Text &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
    \psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox}
\end{tabular*}

\end{document}

enter image description here

Do similarly if you want line breaks in the first cell:

\documentclass{article}
\usepackage{adjustbox}
\usepackage{pst-barcode}
\usepackage[crop=off]{auto-pst-pdf}

\begin{document}

\begin{tabular*}{\textwidth}{@{}l @{\extracolsep{\fill}} r@{}}
\begin{tabular}[t]{@{}l@{}}
Title\\ Text
\end{tabular} &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
    \psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox}
\end{tabular*}

\end{document}

enter image description here

6
  • Thanks a lot! Works fine. Just one more question: is it possible to top-align even when text on the left has line breaks?
    – ajeh
    Jun 20, 2014 at 15:34
  • @ajeh It mostly depends on how you do the line breaks: is the text in a p cell?
    – egreg
    Jun 20, 2014 at 15:35
  • Just what's in MWE. Example: Title\\Text pushes text above the picture :( I am trying to use space below the title for things like 'as of Jun 20, 2014' etc.
    – ajeh
    Jun 20, 2014 at 15:48
  • @ajeh I added a way
    – egreg
    Jun 20, 2014 at 15:59
  • What is the significance of @{}?
    – ajeh
    Jun 20, 2014 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .