如何跨多行列旋转表格中的文本

如何跨多行列旋转表格中的文本
\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{tabularx}
\begin{document}
  \begin{table}[ht]
    \begin{minipage}[b]{1 \linewidth}\centering
      \begin{tabular}{|c|c|c|c|c|}
      \hline
        Tri Sankhya & Vihbakti & Ekavachana & Dvivachana & Bahuvachana \\
      \hline
        Pra Trik    & Prathama & Su (s)     & Au &  \\
        Dvi Trik    & Dvitiya  & Am         & Aut (Au) &  \\
        Tri Trik    & Trutiya  & Ta (A)     & Bhyam & \\ 
        Cha Trik    & Chaturthi& Ne (E)     & Bhyam & \\
        Pan Trik    & Panchami & Nasi (as)  & Bhyam &   \\
        Shas Trik   & Shashthi & Nas (as)   & Os &   \\
        Sap Trik    & Saptami  & Ni (ee)    & Os &   \\
      \hline
      \end{tabular}
      \caption{Subanta Pratyaya}
    \end{minipage}
  \end{table}
\end{document} 

在附图中,我想将文本放置在最后一列,旋转 90 度,但不知道如何操作。此外,我如何才能只为整列的背景着色。

答案1

使用嵌套表格:

\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage{array}
\def\Tab#1{\tabular[t]{>{\rule[-1ex]{0pt}{3ex}}c}#1\endtabular}
\newcolumntype{C}{@{}c@{}}

\begin{document}
\begin{table}[ht]
\centering
 \begin{tabular}{|C|C|C|C|C|}\hline
\Tab{Tri Sankhya \\\hline 
     Pra Trik\\Dvi Trik\\Tri Trik\\Cha Trik\\ Pan Trik\\ Shas Trik\\ Sap Trik}
&
\Tab{Vihbakti\\\hline 
     Prathama\\ Dvitiya\\Trutiya\\Chaturthi\\Panchami\\Shashthi\\Saptami}
&
\Tab{Ekavachana \\\hline
     Su (s)\\Am\\Ta (A)\\Ne (E)\\Nasi (as)\\Nas (as)\\Ni (ee)}
&
\Tab{Dvivachana\\\hline
     Au\\Aut (Au)\\Bhyam\\Bhyam\\Bhyam\\Os\\ Os}
& 
\Tab{Bahuvachana\\\hline
 \cellcolor{blue!20}
  \rotatebox{90}{~\parbox{3.5cm}{%
  Here comes the rotated text, which can also be 
  typeset in several lines.
}~}}  \\\hline
\end{tabular}
\caption{Subanta Pratyaya}
\end{table}

\end{document} 

在此处输入图片描述

关于您的问题,另一种可能性是:

\tabular{@{}|CC|@{}}\hline% the outer one
\begin{tabular}[t]{c|c|c|c|}
 Tri Sankhya& Vihbakti & Ekavachana & Dvivachana \\\hline
  Pra Trik  & Prathama & Su (s)     & Au         \\
  Dvi Trik  & Dvitiya  & Am         & Aut (Au)   \\
  Tri Trik  & Trutiya  & Ta (A)     & Bhyam      \\ 
  Cha Trik  & Chaturthi& Ne (E)     & Bhyam      \\
  Pan   Trik& Panchami & Nasi (as)  & Bhyam      \\
  Shas Trik & Shashthi & Nas (as)   & Os         \\
  Sap Trik  & Saptami  & Ni (ee)    & Os         \\ 
\end{tabular}
&
\begin{tabular}[t]{c}
Bahuvachana\\\hline
 \cellcolor{blue!20}
  \rotatebox{90}{~\parbox{3.2cm}{%
  Here comes the rotated text, which can also be 
  typeset in several lines.
}~}
\end{tabular}\\\hline
\endtabular

但这需要找到正确的列高,这\parbox在第一个例子中是自动完成的

在此处输入图片描述

第三种解决方案也需要手动设置 parbox 宽度:

\begin{tabular}{|c|c|c|c|>{\columncolor{blue!20}}c|}\hline
          Tri Sankhya & Vihbakti    & Ekavachana & Dvivachana & \multicolumn{1}{@{}c|}{Bahuvachana} \\
       \hline
          Pra Trik  & Prathama   & Su (s)& Au &  \\
          Dvi Trik & Dvitiya & Am & Aut (Au) &  \\
          Tri Trik  & Trutiya  & Ta (A) & Bhyam & \\ 
          Cha Trik  & Chaturthi  & Ne (E) & Bhyam & \\
          Pan   Trik & Panchami  & Nasi (as)& Bhyam &   \\
          Shas Trik & Shashthi  & Nas (as)& Os &   \\
          Sap Trik & Saptami & Ni (ee) & Os &   
  \rotatebox{90}{\makebox(0,0)[lc]{~\parbox{3.2cm}{%
  Here comes the rotated text, which can also be 
  typeset in several lines.}~}}
\\\hline
\end{tabular}

答案2

您可以使用该包旋转多行文本adjustbox。它还允许您将官方高度设置为零,以便您可以将其放置在列的最后一个单元格中,同时覆盖上部单元格,而不会干扰单元格大小。

对于这样的小框,您应该使用文本左对齐,最好使用如图所示的\RaggedRightragged2e

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{adjustbox}
\usepackage{ragged2e}
\begin{document}
  \begin{table}[ht]
    \def\C{\cellcolor{blue!50}}
    \begin{minipage}[b]{1 \linewidth}\centering
      \begin{tabular}{|c|c|c|c|c|}
      \hline
        Tri Sankhya & Vihbakti & Ekavachana & Dvivachana & Bahuvachana \\
      \hline
        Pra Trik    & Prathama & Su (s)     & Au & \C  \\
        Dvi Trik    & Dvitiya  & Am         & Aut (Au) & \C  \\
        Tri Trik    & Trutiya  & Ta (A)     & Bhyam & \C \\ 
        Cha Trik    & Chaturthi& Ne (E)     & Bhyam & \C \\
        Pan Trik    & Panchami & Nasi (as)  & Bhyam & \C  \\
        Shas Trik   & Shashthi & Nas (as)   & Os & \C  \\
        Sap Trik    & Saptami  & Ni (ee)    & Os & \C
        \adjustbox{minipage=3.2cm,angle=90,raise={1pt}{0pt}{0pt}}{% raise by 1pt, set height and depth to 0pt.
            \RaggedRight
            Here comes the rotated text, which can also be 
            typeset in several lines.
        }
        \\
      \hline
      \end{tabular}
      \caption{Subanta Pratyaya}
    \end{minipage}
  \end{table}
\end{document} 

结果

相关内容