在表格的第一列中垂直居中对齐文本的简单方法?

在表格的第一列中垂直居中对齐文本的简单方法?

这是我从代码中得到的结果:我的代码输出

\begin{center}
\def\arraystretch{3}
\begin{tabular}{|| c | c | c | c ||}
\hline
\textbf{Posizione}&\shortstack{\textbf{Lunga} \\ \textbf{(long/buy)}}&\shortstack{\textbf{Corta} \\ \textbf{(short/sell)}}\\
\hline
\textbf{Call}&\shortstack{$PL_C^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to+\infty$\\Perdita limitata per:\\\\$S_{t_K}\to 0$}&\shortstack{$PL_C^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to 0$\\Perdita illimitata per:\\\\$S_{t_K}\to +\infty$}\\
\hline
\textbf{Put}&\shortstack{$PL_P^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to0$\\Perdita limitata per:\\\\$S_{t_K}\to+\infty$}&\shortstack{$PL_P^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to +\infty$\\Perdita illimitata per:\\\\$S_{t_K}\to 0$}\\
\hline
\end{tabular}
\end{center}

我希望第一列以简单的方式垂直居中。我发现了类似的问题,但我设法解决的只有几个问题,导致其他文档表发生变化并转移到其他页面。谢谢

答案1

这将替换\shortstack为嵌套表格。我还添加了\bigstrut更多边距以用于特定行。

\documentclass{article}
\usepackage{amsmath}

\newcommand{\subtabular}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}
\newcommand{\bigstrut}{\rule[-1.5\dp\strutbox]{0pt}{1.5\normalbaselineskip}}% \def\arraystretch{1.5}

\begin{document}
\begin{center}
\begin{tabular}{|| c | c | c ||}
\hline
\textbf{Posizione}&
\subtabular{\textbf{Lunga} \\ \textbf{(long/buy)}}&
\subtabular{\textbf{Corta} \\ \textbf{(short/sell)}}\\
\hline
\textbf{Call}&
\subtabular{\bigstrut $PL_C^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to+\infty$\\Perdita limitata per:\\\\$S_{t_K}\to 0$}&
\subtabular{\bigstrut $PL_C^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to 0$\\Perdita illimitata per:\\\\$S_{t_K}\to +\infty$}\\
\hline
\textbf{Put}&
\subtabular{\bigstrut $PL_P^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to0$\\Perdita limitata per:\\\\$S_{t_K}\to+\infty$}&
\subtabular{\bigstrut $PL_P^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to +\infty$\\Perdita illimitata per:\\\\$S_{t_K}\to 0$}\\
\hline
\end{tabular}
\end{center}
\end{document}

演示

答案2

有了包就简单了makecell。无关:我不明白为什么你设置\arraystretch为 3。

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{makecell}

\begin{document}

\begin{table}
\centering
\setcellgapes{4pt}\makegapedcells
\begin{tabular}{|| c | c | c | c ||}
\hline
\textbf{Posizione}&\shortstack{\textbf{Lunga} \\ \textbf{(long/buy)}}&\shortstack{\textbf{Corta} \\ \textbf{(short/sell)}}\\
\hline
\textbf{Call}&\makecell{$PL_C^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to+\infty$\\Perdita limitata per:\\\\$S_{t_K}\to 0$}&\makecell{$PL_C^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to 0$\\Perdita illimitata per:\\\\$S_{t_K}\to +\infty$}\\
\hline
\textbf{Put}&\makecell{$PL_P^{\text{long}}$\\$\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno illimitato per:\\$S_{t_K}\to0$\\Perdita limitata per:\\\\$S_{t_K}\to+\infty$}&\makecell{$PL_P^{\text{short}}$\\$-\max \{S_{t_K}-Z-P_C,-P_C\}$\\Guadagno limitato per:\\$S_{t_K}\to +\infty$\\Perdita illimitata per:\\\\$S_{t_K}\to 0$}\\
\hline
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容