
Quiero incluir una itemize
lista dentro de un table
entorno, de forma compacta para ahorrar espacio. Sin embargo, hay un gran espacio encima de la lista cuando está en la tabla, pero no después de un párrafo en texto normal:
\documentclass[12pt]{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}
\linespread{1}
\usepackage{paralist}
\usepackage{enumitem} % enumerate?
\usepackage{tabularx}
\begin{document}
some text
\begin{compactitem} \item point1 \item point2 \end{compactitem}
\begin{table}[ht!]
\setlength{\leftmargini}{7pt}
\begin{tabularx}{\linewidth}{l | X | X }\hline \hline
& ECB& FED\\ \hline
M1 & \begin{itemize}[noitemsep,topsep=0pt] \item point1 \item point2 \end{itemize}
& \begin{compactitem} \item point1 \item point2 \end{compactitem}
\end{tabularx}
\end{table}
\end{document}
Como puede ver, probé tanto el paquete compactitem
from paralist
como itemize
el from enumitem
con sus opciones [noitemsep,topsep=0pt]
. Producen alturas ligeramente diferentes. Esto funciona entre párrafos normales, pero en la tabla no.Me gustaría que el "punto1" estuviera al mismo nivel que el "M1".
Éste, con una ligera sangría que se ve cuando hay un salto de línea (la palabra "Activos" comienza un poco más a la derecha que la palabra "durante"), es el resultado de
\begin{minipage}[t]{\hsize}\begin{compactitem}
\item Assets can be \textbf{difficult to value} during periods of hyperinflation
\end{compactitem}\end{minipage}
Comparando las dos soluciones propuestas:El siguiente MWE compara las dos soluciones directamente, definiendo nuevos entornos, respectivamente, denominados compactitemt
y compactitemm
.
\documentclass%[12pt,abstracton,titlepage,parskip=false, no, no,twoside=true,open=right]
{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}
%\usepackage{listings}
\usepackage{paralist}
%\usepackage{newtxtext}%antpolt mathpazo %\usepackage{mathptmx} %\usepackage{newtxtext}
\usepackage{enumitem} % enumerate?
\newenvironment{compactitemm}{\begin{minipage}[t]{\hsize}\begin{compactitem}}{\end{compactitem}\end{minipage}} %this solution requires enumitem package
\newenvironment{compactitemt}{\begin{itemize}[nosep, wide=0pt,
%left=0pt %for neat, wide=0pt %for flush left to save space
before={\begin{minipage}[t]{\hsize}},
after ={\end{minipage}} ] }{ \end{itemize} }
\renewcommand{\familydefault}{\sfdefault}
\usepackage{tabularx}
\begin{document}
\begin{table}
\setlength{\leftmargini}{7pt} %this impacts the left margin of itemize package, i.e. ``stuff 2'' in table. 7pt aligns with the other solution.
\begin{tabularx}{\linewidth}{X | X }\hline
\multicolumn{2}{c}{stuff 1}\\ \hline
\begin{compactitemt}
\item x This line should break and we see where the next begins
\item y
\item z
\end{compactitemt}
& \begin{compactitemt}
\item a This line should break and we see where the next begins
\item b
\end{compactitemt}\\ \hline
\multicolumn{2}{c}{stuff 2}\\ \hline
\begin{compactitemm}
\item x This line should break and we see where the next begins
\item y
\item z This line should break and we see where the next begins
\end{compactitemm}
& \begin{compactitemm}
\item a This line should break and we see where the next begins
\item b
\end{compactitemm}\\ \hline
\end{tabularx}
\caption{MWE}
\end{table}
\end{document}
Respuesta1
- Si utiliza el
compactitem
entorno, debe incluirlo en declaraciones\begin{minipage}[t]{\hsize}
y .\end{minipage}
Si usa un
itemize
entorno junto con elenumitem
paquete, puede agregar las declaracionesbefore={\begin{minipage}[t]{\hsize}}, after ={\end{minipage}}
a la lista de opciones que van con
\begin{itemize}
.
\documentclass[12pt]{scrbook}
\usepackage{paralist,enumitem,tabularx}
\begin{document}
\begin{table}[ht!]
\setlength\extrarowheight{2pt} % optional, for a slighly more open "look"
\setlength{\leftmargini}{7pt}
\begin{tabularx}{\linewidth}{l | X | X }
\hline \hline
& ECB & FED\\
\hline
M1 & \begin{itemize}[nosep, left=0pt,
before={\begin{minipage}[t]{\hsize}},
after ={\end{minipage}} ]
\item point1
\item point2
\end{itemize}
& \begin{minipage}[t]{\hsize}
\begin{compactitem}
\item point1
\item point2
\end{compactitem}
\end{minipage}\\
\hline
\end{tabularx}
\end{table}
\end{document}
Respuesta2
Para el espacio de arriba, basta con hacerle creer a LaTeX que la celda es una minipágina. Para ello, tomé prestado un \compress
comando que se encuentra en una respuesta a una pregunta en este sitio. Para el espacio siguiente, debe agregar un \baselineskip negativo al final.
\documentclass[12pt]{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}
\linespread{1}
\usepackage{paralist}
\usepackage{enumitem} % enumerate?
\usepackage{tabularx}
\makeatletter
\newcommand{\compress}{\@minipagetrue}
\makeatother
\begin{document}
some text
\begin{compactitem} \item point1 \item point2 \end{compactitem}
\begin{table}[ht!]
\setlength{\leftmargini}{7pt}
\begin{tabularx}{\linewidth}{l | >{\compress}X |>{\compress} X }\hline \hline
& ECB& FED\\ \hline
M1 & \begin{itemize}[nosep, after=\vspace{-\baselineskip}] \item point1 \item point2 \end{itemize}\\
\hline
& & \begin{compactitem} \item point1 \item point2 \end{compactitem}\leavevmode\vspace*{-\baselineskip}
\\
\hline
\end{tabularx}
\end{table}
\end{document}