
请考虑以下示例:
\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}
我想使其垂直居中Hyppighed
并$h(x)$
相对于图形;我该怎么做?
答案1
您可以使用包m{}
的列来执行此操作array
。我在下面演示了两种方法。第一种是使用m
列,第二种是使用tabularx
包array
。egreg 的回答在这里很方便。m
和X
列都使内容左对齐(它们只是minipage
s)。 如果您希望它们居中,您可以添加>{\centering\arraybackslash}
它们的声明,如下面的代码所示。
\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}
答案2
正如我在评论中所说的那样,这非常非常容易(因为我已经多次做过这种表格)。:-)
\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}
有垂直线和水平线
A{...}{...}{...}
如果需要的话,稍后会解释其中的神奇数字。