我正在使用colortbl
和booktabs
制作下表tcolorbox
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[many]{tcolorbox}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{multirow}
\tcbset{
enhanced,
title=Factorización,
colbacktitle=black,
coltitle=white,
fonttitle=\sffamily\bfseries\Large,
attach boxed title to top right={yshift=-8pt},
boxed title style={
enhanced,
boxrule=0.4mm,
frame code={ \path[tcb fill frame,black] (frame.south west) -- ([yshift=-7pt]frame.north west) -- ([xshift=7pt]frame.north west) -- (frame.north east) -- ([yshift=7pt]frame.south east) -- ([xshift=-7pt]frame.south east);},
interior code={ \path[tcb fill interior,black!75] (interior.south west) -- ([yshift=-7pt]interior.north west) -- ([xshift=7pt]interior.north west) -- (interior.north east) -- ([yshift=7pt]interior.south east) -- ([xshift=-7pt]interior.south east);} },
leftrule=0mm,
toprule=0mm,
colframe=black,
colback=white,
coltext=black,
arc=0pt,
boxsep=0mm,
left=0mm,
right=0mm,
bottom=0mm,
width=12cm,
}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tcolorbox}
\begin{tabular}{
>{\columncolor{gray!50}}P{5cm}|
P{7cm}
}
\addlinespace[1mm]
& $a^{2}+2ab+b^{2}=(a+b)^{2}$ \\
\multirow{2}{*}[12pt]{Trinomio cuadrado perfecto} & $a^{2}-2ab+b^{2}=(a-b)^{2}$ \\
\hline
Diferencia de cuadrados & $a^{2}-b^{2}=(a+b)(a-b)$ \\
\hline
Suma de cubos & $a^{3}+b^{3}=(a+b)(a^{2}-ab+b^{2})$ \\
\hline
Diferencia de cubos & $a^{3}-b^{3}=(a-b)(a^{2}+ab+b^{2})$ \\
\end{tabular}
\end{tcolorbox}
\end{document}
也许我很挑剔,但你可以看到第二、第三和第四行的指数是接触的,\hline
所以为了解决这个问题,我\addlinespace
在每一行中添加了额外的垂直空间,但不幸的是,我得到了这个
使用此代码
\begin{tcolorbox}
\begin{tabular}{
>{\columncolor{gray!50}}P{5cm}|
M{7cm}
}
\addlinespace[1mm]
& $a^{2}+2ab+b^{2}=(a+b)^{2}$ \\
\multirow{2}{*}[12pt]{Trinomio cuadrado perfecto} & $a^{2}-2ab+b^{2}=(a-b)^{2}$ \\
\hline
\addlinespace[0.8mm]
Diferencia de cuadrados & $a^{2}-b^{2}=(a+b)(a-b)$ \\
\hline
\addlinespace[0.8mm]
Suma de cubos & $a^{3}+b^{3}=(a+b)(a^{2}-ab+b^{2})$ \\
\hline
\addlinespace[0.8mm]
Diferencia de cubos & $a^{3}-b^{3}=(a-b)(a^{2}+ab+b^{2})$ \\
\end{tabular}
\end{tcolorbox}
我该如何解决这个垂直和颜色问题。
答案1
你在寻找这样的东西吗:
对于上图,我省略了包booktabs
,为了在方程式中节省更多空间,我使用了一个技巧$\vskip-1ex$
,但重点是使用tabularx
以下能力tcolorbox
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[dvipsname,table]{xcolor}
\usepackage{array,tabularx}
\usepackage[all]{tcolorbox}
\usepackage{minted}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}m{#1}}
\begin{document}
\tcbset{enhanced,
colbacktitle=black, coltitle=white,
fonttitle=\sffamily\bfseries\Large,
attach boxed title to top right={yshift=-4pt},
boxed title style={enhanced,
boxrule=0.4mm,
frame code = {\path[tcb fill frame,black]
(frame.south west) -- ([yshift=-7pt]frame.north west) --
([xshift=7pt]frame.north west) -- (frame.north east) --
([yshift=7pt]frame.south east) -- ([xshift=-7pt]frame.south east);},
interior code ={\path[tcb fill interior,black!75]
(interior.south west) -- ([yshift=-7pt]interior.north west) -- ([xshift=7pt]interior.north west) -- (interior.north east) -- ([yshift=7pt]interior.south east) -- ([xshift=-7pt]interior.south east);}
},
leftrule=0mm,toprule=0mm,
colframe=black,colback=white,coltext=black,
arc=0pt,
boxsep=0mm,
left=0mm,right=0mm,bottom=0mm,
width=12cm,
tabularx={>{\columncolor{gray!30}}X | >{$}P{66mm}<{$}},
}
\begin{tcolorbox}[title=Factorización]\sffamily
Trinomio cuadrado perfecto & $\vskip -1ex$
a^{2}+2ab+b^{2}=(a+b)^{2} \newline
a^{2}-2ab+b^{2}=(a-b)^{2} \\
\hline
Diferencia de cuadrados & a^{2}-b^{2}=(a+b)(a-b) \\
\hline
Suma de cubos & a^{3}+b^{3}=(a+b)(a^{2}-ab+b^{2}) \\
\hline
Diferencia de cubos & a^{3}-b^{3}=(a-b)(a^{2}+ab+b^{2})
% \hline
\end{tcolorbox}
\end{document}
升级: 不太优雅的可能解决方案,不需要安装 python 和 minted 包:
\documentclass[border=3mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[many]{tcolorbox}
\usepackage{colortbl}
\tcbset{enhanced,
top=0pt,
boxrule=0.4mm,
%
colbacktitle=black,coltitle=white,
fonttitle=\sffamily\bfseries\Large,
attach boxed title to top right={yshift=-8pt},
boxed title style = {enhanced,
frame code={\path[tcb fill frame,black]
(frame.south west) -- ([yshift=-7pt]frame.north west) -- ([xshift=7pt]frame.north west) -- (frame.north east) -- ([yshift=7pt]frame.south east) -- ([xshift=-7pt]frame.south east);},
interior code={\path[tcb fill interior,black!75]
(interior.south west) -- ([yshift=-7pt]interior.north west) -- ([xshift=7pt]interior.north west) -- (interior.north east) -- ([yshift=7pt]interior.south east) -- ([xshift=-7pt]interior.south east);} },
leftrule=0.4mm,
toprule=0.4mm,
colframe=black,colback=white,coltext=black,
arc=0pt,
boxsep=0mm,
left=0mm,right=0mm,bottom=0mm,width=12cm,
}
\usepackage{array}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcommand\rspace{\rule[-5pt]{0pt}{15pt}}
\begin{document}
\begin{tcolorbox}[title=Factorización]\sffamily
\begin{tabular}{>{\columncolor{gray!50}}P{5cm}|>{$}P{6.1cm}<{$}}
Trinomio cuadrado perfecto & $\vskip-0.5ex$
a^{2}+2ab+b^{2}=(a+b)^{2} \newline
a^{2}-2ab+b^{2}=(a-b)^{2} \\
\hline
Diferencia de cuadrados & a^{2}-b^{2}=(a+b)(a-b) \rspace\\
\hline
Suma de cubos & a^{3}+b^{3}=(a+b)(a^{2}-ab+b^{2}) \rspace\\
\hline
Diferencia de cubos & a^{3}-b^{3}=(a-b)(a^{2}+ab+b^{2}) \rspace\\
\end{tabular}
\end{tcolorbox}
\end{document}
它给出的结果与以前相同。但是它需要更多的手动调整。