tcolorbox: cómo hacer una variante de mylib

Aug 16 2020

Esta pregunta :

Cómo reproducir este cuadro en tcolorbox

tiene una respuesta clara. Quería hacer una variante similar con dos pequeños cambios:

-en lugar de LIB, use OBSERVACIONES (ok, eso es trivial)

-formatear el texto en viñetas (detallar el entorno)

\newtcbox{\myremarks}{enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=0mm,bottom=0mm,
  right=0mm,left=4mm,arc=1pt,boxsep=2pt,before upper={\vphantom{dlg}},
  colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
  overlay={\begin{tcbclipinterior}\fill[green!75!blue!50!white] (frame.south west)
    rectangle node[text=white,font=\sffamily\bfseries\tiny,rotate=90] {REMARKS} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}


\NewDocumentCommand\remarks{m} 
{\myremarks{\begin{itemize} #1\end{itemize}}}

fallará en esto:

\remarks
{
\item Perfect relationships of $r=\pm1$ do not exist in the real world.
\item Correlation does not imply causation
}

falla al notar que falta un elemento, por lo que hay algún tipo de problema de análisis.

Es probable que la forma ideal de hacer esto sea modificar el newtcbox directamente para que formatee el texto en el elemento, pero ni siquiera sé por dónde empezar a hacerlo.

Respuestas

2 muzimuzhiZ Aug 17 2020 at 05:05

Prueba esto:

  • varwidth upper=\linewidthSe usa la opción (con el varwidthpaquete cargado) para permitir \myremarkscomponer su argumento en modo párrafo, que es requerido por el itemizeentorno. Esto es equivalente a \myremarks{\begin{varwidth}{\linewidth} ...\end{varwidth}}.
  • Dado que el texto girado REMARKSes superior a la altura mínima de \myremarks, la opción height from=1.2cm to \maxdimense utiliza para establecer una altura mínima.
  • pos=1, anchor=south eastSe agregan opciones de nodo para adjuntar texto REMARKSen la parte superior, en lugar de centrarse verticalmente.
  • enumitemlas opciones noitemsep, leftmargin=5mmson para ajustar espacios de itemize.
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{xparse}

\newtcbox{\myremarks}{
  enhanced,nobeforeafter,tcbox raise base,
  boxrule=0.4pt,top=0mm,bottom=0mm,
  right=0mm,left=4mm,arc=1pt,boxsep=2pt,
  before upper={\vphantom{dlg}},
  colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
  overlay={
    \begin{tcbclipinterior}
      \fill[green!75!blue!50!white] 
        (frame.south west) rectangle 
          node[text=white,font=\sffamily\bfseries\tiny,rotate=90, pos=1, anchor=south east] {REMARKS}
        ([xshift=4mm]frame.north west);
    \end{tcbclipinterior}
  },
  % equivalent to surround the cmd arg in "varwidth" env
  varwidth upper=\linewidth,
  % set minimum height for complete output of rotated "REMARKS"
  height from=1.2cm to \maxdimen,
}

\NewDocumentCommand\remarks{m}{%
  \myremarks{%
    \begin{itemize}[noitemsep, leftmargin=5mm]
      #1%
    \end{itemize}
  }%
}

\begin{document}
\remarks{
  \item abc
}

\remarks{
  \item abc
  \item def
  \item ghi
}
\end{document}