2

When using PsPicture inside a tabular, aligning the picture to the top works fine using \raisebox{} as shown in tabular no. 1. I archieved additional space under the picture using \vspace. (Is there a better way to do it???)

Now, I would like to align a formula inside the left cell at the bottom while a PsPicture is located in the right cell. As shown in tabular no. 2, row no. 1, it works fine. But I intend to add a small space above the PsPicture using \vspace again. Unfortunately, the aligning of the text at the bottom works no more. How can I get the required space above the picture and align the formula to the bottom?

enter image description here



\documentclass[a4paper,DIV=15,oneside,12pt]{scrartcl}
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{graphicx}
\usepackage{array}
\usepackage{calc}
\usepackage{setspace}
\usepackage{pst-all}
\usepackage{auto-pst-pdf}

\newcolumntype{D}[1]{>{\Centering}p{#1}}

\begin{document}
\onehalfspacing
\begin{tabular}{|p{0.47\textwidth}|D{0.47\textwidth}|}
\hline
Formula & 
\raisebox{-\height+0.5\baselineskip}{
\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}}\vspace{0.1cm}\\\hline
\end{tabular}
\vspace{\baselineskip}

\begin{tabular}{|b{0.47\textwidth}|D{0.47\textwidth}|}
\hline
Formula &
\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}\\\hline
Formula & \vspace*{0.1cm}
\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}\\\hline
\end{tabular}
\end{document}
CarLaTeX
  • 62,716
Gotti91
  • 509

2 Answers2

1

Two solutions:

  • use booktabs and no vertical rules: the rules of booktabs have some vertical (adjustable) padding around them. The table xwill look more professional;
  • use \raisebox{0pt}[\dimexpr\height+some length] to fool LaTeX and make it believe the figure height is slightly larger than its natural height.

Here is an example of both solutions:

\documentclass[a4paper,DIV=15,oneside,12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs} 
\usepackage{ragged2e}
\usepackage{graphicx}
\usepackage{array}
\usepackage{setspace}
\usepackage{pst-all}
\usepackage{auto-pst-pdf}

\newcolumntype{D}[1]{>{\Centering}p{#1}}

\begin{document}

\onehalfspacing

\begin{tabular}{b{0.47\textwidth}D{0.47\textwidth}}
\toprule
Formula &
\raisebox{0pt}[\dimexpr\height+5pt]{\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}}\\\midrule
Formula &
\raisebox{0pt}[\dimexpr\height+5pt]{\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}}\\\bottomrule
\end{tabular}

\vspace{\baselineskip}

\begin{tabular}{|b{0.47\textwidth}|D{0.47\textwidth}|}
\hline
Formula &
\raisebox{0pt}[\dimexpr\height+5pt]{\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}}\\\hline
Formula &
\raisebox{0pt}[\dimexpr\height+5pt]{\begin{pspicture}
\psframe(0,0,)(6,5)
\end{pspicture}}\\\hline
\end{tabular}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Good solution, thank you very much. What is the function of \dimexpr? – Gotti91 Feb 22 '17 at 09:22
  • It's an etex primitive: it makes arithmetic operation on lengths. There are similar \numexpr and \glueexpr. It should end with relax (which I didn't have to do because of the ] at the end. You may look at this answer on this site for more details. – Bernard Feb 22 '17 at 09:46
  • So far so good, but is it really necessary? I removed the \dimexprand got the same result ... Just a coincidence? – Gotti91 Feb 22 '17 at 11:10
  • It's. You load calc, and I prefer to use the etex primitives. Without cal, or \dimexpr, it won't work. B.t.w., I forgot to remove calc loading. – Bernard Feb 22 '17 at 12:58
  • New problem: If I have a pspicture in the left and the right cell (see on top, same picture instead of "formula"), how can I shift the pictures different? For example, left picture 5pt as shown above, but right picture 3cm? Using raisebox{0cm}[\height+5pt+3cm] on the right picture shifts both pictures 3cm instead of just the right one ... – Gotti91 Feb 23 '17 at 00:12
  • I have some difficulty to see what you mean precisely. Could you post some sketch (hand-made) explaining it visually? – Bernard Feb 23 '17 at 00:21
  • [https://i.stack.imgur.com/gURcs.jpg] – Gotti91 Feb 23 '17 at 01:04
  • @Gotti: I've posted a code fragment in chat. – Bernard Feb 23 '17 at 01:07
0

Use coordinates for pspicture! And if you need negative coordinates, then use the option shift for moving it up.

\documentclass[a4paper,DIV=15,oneside,12pt]{scrartcl}
\usepackage{booktabs} 
\usepackage{ragged2e}
\usepackage{array}
\usepackage{pst-all}    
\newcolumntype{D}[1]{>{\Centering}p{#1}}    
\begin{document}

\begin{tabular}{b{0.47\textwidth}D{0.47\textwidth}}\toprule
Formula & \begin{pspicture}(6,5.1) \psframe(6,5)\end{pspicture}\\\midrule
Formula & \begin{pspicture}(6,5.1) \psframe(6,5)\end{pspicture}\\\bottomrule
\end{tabular}

\bigskip
\begin{tabular}{|b{0.47\textwidth}|D{0.47\textwidth}|}\hline
Formula & \begin{pspicture}(6,5.2)\psframe(6,5)\end{pspicture}\\\hline
Formula & \begin{pspicture}(6,5.2)\psframe(6,5)\end{pspicture}\\\hline
\end{tabular}

\end{document}

enter image description here

  • So I guess it's \usepackage[crop=off]{auto-pst-pdf} for PDFLaTeX then? – Gotti91 Feb 22 '17 at 13:41
  • crop=off is only needed when no Perl is installed. However, use xelatex and you do not need auto-pst-pdf. –  Feb 22 '17 at 13:43
  • I see. Using no coordinates for pspicture has been a quite comfortable ... no need to test out as every picture had the right "dimensions" ... additionally no cropped corners, seems to have been done by the package auto-pst-pdf itself ... But why is it so important to use the coordinates? – Gotti91 Feb 22 '17 at 23:26
  • without specifying coordinates, it takes always (10cm,10cm) which makes only sense when images are cropped! –  Feb 23 '17 at 08:24