![带 tcolorbox 的 SWOT 表](https://linux22.com/image/406484/%E5%B8%A6%20tcolorbox%20%E7%9A%84%20SWOT%20%E8%A1%A8.png)
我正在努力适应这SWOT 表格示例符合我的需要。除了两个我无法解决的问题外,一切都很好:
- 从示例中删除一些文本后,重新将标题文本水平和垂直居中。我尝试过参数
\tcbset
,但找不到让两个标题都居中的方法 - 删除枚举缩进。我尝试过
[leftmargin=*]
,但在这种情况下,代码不会产生理想的输出。
我此刻的代码如下:
\documentclass[10pt]{article}
\usepackage{times}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\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}
\newcommand{\texta}{Helpful}
\newcommand{\textb}{Harmful}
\newcommand{\textcn}{\rotatebox[origin=c]{90}{\parbox[t]{3cm}{\centering Internal origin\\}}}
\newcommand{\textdn}{\rotatebox[origin=c]{90}{\parbox[b]{3cm}{\centering External origin\\}}}
\newcommand{\texts}{strength 1\par strength 2}
\newcommand{\textw}{weakness 1\par weakness 2}
\newcommand{\texto}{opportunity 1\par opportunity 2}
\newcommand{\textt}{threat 1\par threat 2}
\tcbset{swotbox/.style={size=normal, boxrule=0pt,
colback=#1, watermark text=#1, width=.5\linewidth-5mm},
header/.style={size=normal, boxrule=0pt, width=.5\linewidth-5mm, colback=#1, valign=center, halign=center},
firstcol/.style={header=#1, width=1cm}
}
\begin{document}
\begin{tcbitemize}[raster columns=3, raster rows=3, enhanced, sharp corners, raster equal height=rows, raster force size=false, raster column skip=0pt, raster row skip = 0pt]
%Empty corner and two headers
\tcbitem[blankest, width=1cm]
\tcbitem[header = helpful]
\texta
\tcbitem[header = harmful]
\textb
%First row
\tcbitem[firstcol = internal]
\textcn
\tcbitem[swotbox = S]
\begin{enumerate}
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\tcbitem[swotbox = W]
\begin{enumerate}
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
%Second row
\tcbitem[firstcol = external]
\textcn
\tcbitem[swotbox=O]
\begin{enumerate}
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\tcbitem[swotbox=T]
\begin{enumerate}
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\end{tcbitemize}
\end{document}
答案1
左列对齐的问题是由于boxsep
值造成的。此框的宽度不足以满足 boxep(默认值为 1mm)和旋转后的 parbox 高度。如果修复,则可以看到boxsep=0pt
的效果。halign=center
关于项目列表对齐的第二个问题可以通过enumitem
包并应用于labelindent=\parindent,leftmargin=*
所需的项目列表来解决。
\documentclass[10pt]{article}
\usepackage{times}
\usepackage[most]{tcolorbox}
\usepackage{enumitem}
\usepackage{lipsum}
\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}
\newcommand{\texta}{Helpful}
\newcommand{\textb}{Harmful}
\newcommand{\textcn}{\rotatebox{90}{\parbox[c]{3cm}{\centering Internal origin}}}
\newcommand{\textdn}{\rotatebox{90}{\parbox[c]{3cm}{\centering External origin}}}
\newcommand{\texts}{strength 1\par strength 2}
\newcommand{\textw}{weakness 1\par weakness 2}
\newcommand{\texto}{opportunity 1\par opportunity 2}
\newcommand{\textt}{threat 1\par threat 2}
\tcbset{swotbox/.style={size=normal, boxrule=0pt,
colback=#1, watermark text=#1, width=.5\linewidth-5mm},
header/.style={size=normal, boxrule=0pt, width=.5\linewidth-5mm, colback=#1, valign=center, halign=center},
firstcol/.style={header=#1, width=1cm, boxsep=0mm}
}
\begin{document}
\begin{tcbitemize}[raster columns=3, raster rows=3, enhanced, sharp corners, raster equal height=rows, raster force size=false, raster column skip=0pt, raster row skip = 0pt]
%Empty corner and two headers
\tcbitem[blankest, width=1cm]
\tcbitem[header = helpful]
\texta
\tcbitem[header = harmful]
\textb
%First row
\tcbitem[firstcol = internal]
\textcn
\tcbitem[swotbox = S]
\begin{enumerate}[labelindent=\parindent,leftmargin=*]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\tcbitem[swotbox = W]
\begin{enumerate}[labelindent=\parindent,leftmargin=*]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
%Second row
\tcbitem[firstcol = external]
\textdn
\tcbitem[swotbox=O]
\begin{enumerate}[labelindent=\parindent,leftmargin=*]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\tcbitem[swotbox=T]
\begin{enumerate}[labelindent=\parindent,leftmargin=*]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\end{tcbitemize}
\end{document}