Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following example:

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{booktabs}


\psset{
  unit = 0.7,
  dimen = middle,
  ticks = none,
  labels = none
}

\newcommand*\pind[2]{%
 \psset{linecolor = red}
  \psline(#1,0)(#1,#2)
  \psline(!#1 0.2 sub #2)(!#1 0.2 add #2)
}
\newcommand*\enkeltobservationer{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \pind{0.5}{3}
    \pind{1.0}{5}
    \pind{1.5}{3}
    \pind{2.0}{3}
    \pind{2.5}{4}
    \pind{3.0}{2}
    \pind{3.5}{5}
    \pind{4.0}{1}
    \pind{4.5}{4}
    \pind{5.0}{2}
  \end{pspicture}%
}
\newcommand*\soejle[2]{%
 \psset{fillcolor = red}
  \psframe[fillstyle = solid](!#1 0.5 sub 0)(#1,#2)
}
\newcommand*\intervaller{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \soejle{0.5}{3}
    \soejle{1.0}{5}
    \soejle{1.5}{3}
    \soejle{2.0}{3}
    \soejle{2.5}{4}
    \soejle{3.0}{2}
    \soejle{3.5}{5}
    \soejle{4.0}{1}
    \soejle{4.5}{4}
    \soejle{5.0}{2}
  \end{pspicture}%
}


\begin{document}

\begin{table}
 \centering
  \begin{tabular}{l c c c}
    \toprule
     Begreb               &
     Forkortelse          &
     Enkeltobservationer  &
     Intervaller            \\
     \midrule
     Hyppighed            &
     $h(x)$               &
     \enkeltobservationer &
     \intervaller           \\
    \bottomrule
   \end{tabular}
\end{table}

\end{document}

output

I would like to vertically center Hyppighed and $h(x)$ relative to the figures; how do I do that?

share|improve this question
    
Does this help: tex.stackexchange.com/a/147393/18228? –  Kevin C Nov 30 '13 at 0:55
    
@KevinC I cannot get it to work. Can I make you give an answer? :) –  Svend Tveskæg Nov 30 '13 at 1:03
    
@DonutE.Knot And I think your comment is arrogant. –  Svend Tveskæg Nov 30 '13 at 1:18
2  
I can't get your code to compile... There's some error with the command \clipbox being already defined. But take a look at this, it might help: tex.stackexchange.com/a/46390/18228 –  Kevin C Nov 30 '13 at 1:24
1  

2 Answers 2

up vote 3 down vote accepted

You can do this with the m{} column of array package. I have demonstrated two ways below. First one using m column and second one using tabularx with array package. egreg's answer comes handy here. Both m and X columns make the contents left anigned (they are just minipages). If you want them centered you can add >{\centering\arraybackslash} in their declarations as in the code below.

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{pstricks-add}
\usepackage{booktabs,array,,tabularx,calc}


\psset{
  unit = 0.7,
  dimen = middle,
  ticks = none,
  labels = none
}

\newcommand*\pind[2]{%
 \psset{linecolor = red}
  \psline(#1,0)(#1,#2)
  \psline(!#1 0.2 sub #2)(!#1 0.2 add #2)
}
\newcommand*\enkeltobservationer{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \pind{0.5}{3}
    \pind{1.0}{5}
    \pind{1.5}{3}
    \pind{2.0}{3}
    \pind{2.5}{4}
    \pind{3.0}{2}
    \pind{3.5}{5}
    \pind{4.0}{1}
    \pind{4.5}{4}
    \pind{5.0}{2}
  \end{pspicture}%
}
\newcommand*\soejle[2]{%
 \psset{fillcolor = red}
  \psframe[fillstyle = solid](!#1 0.5 sub 0)(#1,#2)
}
\newcommand*\intervaller{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \soejle{0.5}{3}
    \soejle{1.0}{5}
    \soejle{1.5}{3}
    \soejle{2.0}{3}
    \soejle{2.5}{4}
    \soejle{3.0}{2}
    \soejle{3.5}{5}
    \soejle{4.0}{1}
    \soejle{4.5}{4}
    \soejle{5.0}{2}
  \end{pspicture}%
}


\begin{document}

\begin{table}
 \centering
  \begin{tabular}{l c   
                    >{\centering\arraybackslash}m{.35\linewidth}
                    >{\centering\arraybackslash}m{.35\linewidth}}
    \toprule
     Begreb               &
     Forkortelse          &
     Enkeltobservationer  &
     Intervaller            \\
     \midrule
     Hyppighed            &
     $h(x)$               &
     \enkeltobservationer &
     \intervaller           \\
    \bottomrule
   \end{tabular}
\end{table}

\begin{center}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\textwidth}{m{\widthof{Hyppighed}}
                             >{\centering\arraybackslash}m{\widthof{Forkortelse}}
                             >{\centering\arraybackslash}X
                             >{\centering\arraybackslash}X}    %%% \widthof from calc package
  \toprule
     Begreb               &
     Forkortelse          &
      Enkeltobservationer  &               
      Intervaller            \\             
     \midrule
     Hyppighed            &
     $h(x)$               &                %%% \centering added to declaration above
     \enkeltobservationer &
     \intervaller           \\
    \bottomrule
\end{tabularx}
\end{center}

\end{document}

enter image description here

share|improve this answer
    
Nice. Thank you. –  Svend Tveskæg Nov 30 '13 at 10:01
    
The last 2 titles are not centered. –  stalking is prohibited Nov 30 '13 at 12:49
    
@DonutE.Knot As your wish sir :-) –  Harish Kumar Dec 1 '13 at 0:41
    
Thank you madam for the update. :-) –  stalking is prohibited Dec 1 '13 at 0:53
1  
@DonutE.Knot hihi, but it is not madam –  Harish Kumar Dec 1 '13 at 0:59

As what I said in the comment, it is very very easy (as I have done this kind of table many times). :-)

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{pstricks-add}
\usepackage{array}
\usepackage{booktabs}

\newcolumntype{A}[3]{%
    >{\minipage{\dimexpr#1\linewidth-#2\tabcolsep-#3\arrayrulewidth}\vspace\tabcolsep}%
    c
    <{\vspace\tabcolsep\endminipage}}


\psset
{
  unit = 0.7,
  dimen = middle,
  ticks = none,
  labels = none
}

\newcommand*\pind[2]{%
 \psset{linecolor = red}
  \psline(#1,0)(#1,#2)
  \psline(!#1 0.2 sub #2)(!#1 0.2 add #2)
}
\newcommand*\enkeltobservationer{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \pind{0.5}{3}
    \pind{1.0}{5}
    \pind{1.5}{3}
    \pind{2.0}{3}
    \pind{2.5}{4}
    \pind{3.0}{2}
    \pind{3.5}{5}
    \pind{4.0}{1}
    \pind{4.5}{4}
    \pind{5.0}{2}
  \end{pspicture}%
}
\newcommand*\soejle[2]{%
 \psset{fillcolor = red}
  \psframe[fillstyle = solid](!#1 0.5 sub 0)(#1,#2)
}
\newcommand*\intervaller{%
  \begin{pspicture}(-0.5,-0.2)(5.9,6.3)
    \psaxes{->}(0,0)(-0.2,-0.2)(5.4,5.5)[\small{$x$},0][\small{$h(x)$},90]
    \soejle{0.5}{3}
    \soejle{1.0}{5}
    \soejle{1.5}{3}
    \soejle{2.0}{3}
    \soejle{2.5}{4}
    \soejle{3.0}{2}
    \soejle{3.5}{5}
    \soejle{4.0}{1}
    \soejle{4.5}{4}
    \soejle{5.0}{2}
  \end{pspicture}%
}


\begin{document}


  \begin{tabular}{A{0.15}{2}{1.5} >{\centering}A{0.15}{2}{1} >{\centering}A{0.35}{2}{1} >{\centering}A{0.35}{2}{1.5}}
    \toprule
     Begreb               &
     Forkortelse          &
     Enkeltobservationer  &
     Intervaller            \tabularnewline\hline
     \midrule
         Hyppighed                      &
     $h(x)$               &
     \enkeltobservationer &
     \intervaller                   \tabularnewline\hline
    \bottomrule
   \end{tabular}


\end{document}

enter image description here

With vertical and horizontal lines

enter image description here

The magic numbers in A{...}{...}{...} will be explained later if requested.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.