4

I have lost hours to this... How do I align a series of tcolorboxes based on the first baseline (or a certain mm of shift). I'll have somewhere around 60 of these per document, and 15 documents...I need a fix! Or an alternative way to the same visual result

What I have:

\usepackage[most]{tcolorbox}
\tcbset{sharp corners, frame hidden, boxrule=0mm, colframe=white, box align=top}

later in document

\begin{enumerate}
\item \begin{tcolorbox}{(Proof 1.1) For $a$ and $b$, two elements of a Field $F$, using only the axioms for a field, proofs:}\end{tcolorbox}
\begin{itemize}
\item \openq $\forall a \in F$, $0a = 0$ \closeq

...

There has to be a way...

The grey boxes need to line up with the first line NEXT to the number/bullet

  • Also, I'd defined these, to clear confusion: \newcommand{\openq}{\begin{tcolorbox}} \newcommand{\closeq}{\end{tcolorbox}} – Mihika Shilpi Aug 31 '18 at 21:18
  • welcome to tex.se! (i) please provide small but complete document beginning with \documentclass... and ending by \end{document}! (ii) do you really need tcolorbox? from image i see that colorbox from thexcolor` package should be suficient and better suited to your need. – Zarko Aug 31 '18 at 21:25
  • @Zarko Apologies, will post complete latex next time! tcolorbox is needed because with colorbox I couldn't get good text wrap and spacing settings - which I need for some longer section blocks as the document progresses. – Mihika Shilpi Sep 01 '18 at 14:44

1 Answers1

5

I propose this hack, with enumitem:

\documentclass[11pt, a4paper]{article}

\usepackage[utf8]{inputenc} %Character set
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\tcbset{sharp corners, frame hidden, boxrule=0mm, colframe=white, box align=top}
\newcommand{\openq}{\begin{tcolorbox}}
\newcommand{\closeq}{\end{tcolorbox}}

\makeatletter
\def\tcbboxsep{\kvtcb@boxsep}
\def\tcbtopsep{\kvtcb@topsep}
\makeatother

\begin{document}

\begin{enumerate}[nosep]
\item \leavevmode\vspace*{-\dimexpr2\baselineskip + \tcbboxsep + \tcbtopsep}
\begin{tcolorbox}{(Proof 1.1) For $a$ and $b$, two elements of a Field $F$, using only the axioms for a field, proofs:}\end{tcolorbox}
\begin{itemize}[nosep, wide=0pt, leftmargin=*]
\item \leavevmode\vspace*{-\dimexpr2\baselineskip + \tcbboxsep +\tcbtopsep}
\openq $\forall a \in F$, $0\,a = 0$ \closeq
\end{itemize}
\end{enumerate}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Thank you @Bernard! Took me a bit of internet digging to understand what the string \leavevmode\vspace*{-\dimexpr2\baselineskip + \tcbboxsep + \tcbtopsep} was doing, other than fixing my problem! I used it without the added sep, and adding some additional spacing of my own that I wanted, but this was a great hack! I put it into a command so that it applies across the board. – Mihika Shilpi Sep 01 '18 at 14:47
  • I don't always explain the details of a code, if I think it would be lengthy and not very useful for the average user. However, I very gladly explain when I'm asked to,so really feel free to ask! – Bernard Sep 01 '18 at 15:18
  • I’m afraid a page break can occur after the \vspace*{...}. I’m not sure that adding \nopagebreak would fix it, some experiments are in order. – egreg Sep 01 '18 at 16:06
  • @egreg: It's only a proposed hack… Please let me know if you find problems. – Bernard Sep 01 '18 at 16:55