我想制作一个带有旋转文本和项目的经典 SWOT 表,但这会导致一些问题。
问题A:旋转后的文本未居中(见彩色单元格)
问题B:itemize 中的项目从右线下方开始。
我确实找到了另一个类似的例子这里不幸的是,我认为我没有很好地理解这个解决方案。
尝试 1:居中和居中上方的空间是错误的
尝试2:居中是“固定的”(受保护的空间~
和非常丑陋\llp
)。我真的不想手动对大约 30 个表格执行此操作。 itemize 上方的间距仍然太长。
问题:我该如何解决这个问题?有没有更好的方法让旋转后的文本居中?请查看附件中的代码和尝试图片。
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{rotating, graphicx}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{array}
\usepackage{tabularx}
\usepackage{rotating}
\usepackage{enumitem}
\usepackage{makecell}
% Colours from http://www.mostlycolor.ch/2013/10/colored-blocks-in-beamer.html
\colorlet{helpful}{lime!70}
\colorlet{harmful}{red!30}
\colorlet{internal}{yellow!20}
\colorlet{external}{cyan!30}
\colorlet{S}{helpful!50!internal}
\colorlet{W}{harmful!50!internal}
\colorlet{O}{helpful!50!external}
\colorlet{T}{harmful!50!external}
\colorlet{Tr}{red!50}
% Attempt 1 to make a good table Nr. 1
\newcommand{\swotTabOne}[4]{
\begin{tabularx}{\textwidth}{|m{1em}X|m{1em}X|}\hline
\cellcolor{S}\rotatebox{90}{Stärken} & \begin{itemize}[leftmargin=*,noitemsep] #1 \end{itemize} &
\cellcolor{W}\rotatebox{90}{Schwächen } & \begin{itemize}[leftmargin=*,noitemsep] #2 \end{itemize}\\ \hline
\cellcolor{O}\rotatebox{90}{Chancen } & \begin{itemize}[leftmargin=*,noitemsep] #3 \end{itemize}&
\cellcolor{Tr}\rotatebox{90}{Risiken } & \begin{itemize}[leftmargin=*,noitemsep] #4 \end{itemize}\\ \hline
\end{tabularx}
}
% Attempt 2
\newcommand{\swotTabTwo}[4]{
\begin{tabularx}{\textwidth}{|m{1em}X|m{1em}X|}\hline
\cellcolor{S}\rotatebox{90}{\llap{Strengths~~~~~}} & {\begin{itemize}[leftmargin=*,noitemsep]\raggedright #1 \end{itemize}} &
\cellcolor{W}\rotatebox{90}{\llap{Schwächen~~~~~}} & \begin{itemize}[leftmargin=*,noitemsep]\raggedright #2 \end{itemize}\\ \hline
\cellcolor{O}\rotatebox{90}{\llap{Chancen }} & \begin{itemize}[leftmargin=*,noitemsep]\raggedright #3 \end{itemize}&
\cellcolor{Tr}\rotatebox{90}{\llap{Risiken~ }} & \begin{itemize}[leftmargin=*,noitemsep]\raggedright #4 \end{itemize}\\ \hline
\end{tabularx}
}
\begin{document}
\begin{table}[htb]
\caption{SWOT analysis for Idea 2}\label{tab:swot_1}
\swotTabOne{\item strength 1 \item this is a very long strength, so much length wow \item another very long strength, absoluteley amzing such wow}
{\item weakness 1 \item weakness 2 \item weakness 3}
{\item amazing opportunity \item oh wow so much opportunity}
{\item risk \item oh this damn risk}
\end{table}
\begin{table}[htb]
\caption{SWOT analysis for Idea 2}\label{tab:swot_2}
\swotTabTwo{\item strength 1 \item this is a very long strength, so much length wow \item another very long strength, absoluteley amzing such wow}
{\item weakness 1 \item weakness 2 \item weakness 3}
{\item amazing opportunity \item oh wow so much opportunity}
{\item risk \item oh this damn risk}
\end{table}
\end{document}
答案1
以下答案中的垂直居中并不完美,但我敢说它比 OP 的例子要好。
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} % <-- new
\usepackage{rotating}
\usepackage[table]{xcolor} % <-- new
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}} % <-- new
\usepackage{enumitem,ragged2e}
\newlist{myitemize}{itemize}{1} % <-- new
\setlist[myitemize]{label=\textbullet,left=0pt,noitemsep,
before={\RaggedRight\begin{minipage}{\hsize}},
after={\end{minipage}}}
%\usepackage{makecell}
% Colours from http://www.mostlycolor.ch/2013/10/colored-blocks-in-beamer.html
\colorlet{helpful}{lime!70}
\colorlet{harmful}{red!30}
\colorlet{internal}{yellow!20}
\colorlet{external}{cyan!30}
\colorlet{S}{helpful!50!internal}
\colorlet{W}{harmful!50!internal}
\colorlet{O}{helpful!50!external}
\colorlet{T}{harmful!50!external}
\colorlet{Tr}{red!50}
% Attempt 1 to make a good table Nr. 1
\newcommand{\swotTabOne}[4]{%
\begin{tabularx}{\textwidth}{| m{1em} X m{1em} X |}
\hline
\cellcolor{S}\rotatebox{90}{Stärken}
& \begin{myitemize} #1 \end{myitemize}
& \cellcolor{W}\rotatebox{90}{Schwächen }
& \begin{myitemize} #2 \end{myitemize}\\
\hline
\cellcolor{O}\rotatebox{90}{Chancen }
& \begin{myitemize} #3 \end{myitemize}
& \cellcolor{Tr}\rotatebox{90}{Risiken }
& \begin{myitemize} #4 \end{myitemize}\\
\hline
\end{tabularx}
}
\begin{document}
\setcounter{chapter}{2} % just for this example
\begin{table}[htb]
\caption{SWOT analysis for Idea 2}
\label{tab:swot_1}
\swotTabOne%
{\item strength 1\strut \item this is a very long string, so
much length wow \item another very long string, absoluteley
amazing such wow}
{\item weakness 1 \item weakness 2 \item weakness 3}
{\item amazing opportunity \item oh wow so much opportunity}
{\item risk \item oh this damn risk}
\end{table}
\end{document}
答案2
使用tabularray
包后,垂直居中并不完美,但它是一个相当好的近似值:
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[skip=1ex]{caption}
\usepackage{xcolor}
\usepackage{rotating, makecell}
\usepackage{tabularray}
\UseTblrLibrary{varwidth}
\usepackage{enumitem}
\newlist{tabitemize}{itemize}{1}% <-- defined new list
\setlist[tabitemize]{nosep, % <-- new list setup
leftmargin = * ,
label = $\bullet$ ,
before = \vspace{-\baselineskip},
after = \vspace{-\baselineskip}
}
\begin{document}
\begin{table}[htb]
\caption{SWOT analysis for Idea 2}\label{tab:swot_2}
\label{tab:table-tblr}
\settowidth\rotheadsize{Schwächen} % from makecell
\begin{tblr}{hlines, vlines,
colspec = {Q[m] X[1.2,l,m] Q[c,m] X[0.8,l,m]},
measure = vbox, % <----
column{1,3} = {cmd=\rotcell}, % <----
}
\SetCell[c=1]{bg=yellow!30} \hfil Stärken
& \begin{tabitemize}
\item strength 1
\item this is a very long strength, so much length wow
\item another very long strength, absolutely amazing such wow
\end{tabitemize}
& \SetCell[c=1]{bg=red!30} Schwächen
& \begin{tabitemize}
\item weakness 1
\item weakness 2
\item weakness 3
\end{tabitemize} \\
\SetCell[c=1]{bg=olive!30} \hfil Chancen
& \begin{tabitemize}
\item amazing opportunity
\item oh wow so much opportunity
\end{tabitemize}
& \SetCell[c=1]{bg=purple!30} \hfil Risiken
& \begin{tabitemize}
\item risk
\item oh this damn risk
\end{tabitemize} \\
\end{tblr}
\end{table}
\end{document}