平均能量损失

平均能量损失

我有一些\items想放在盒子里的东西。我希望盒子有 2 个可以传递的参数

  • 盒子的颜色

  • 盒子的绳子

相关研究

我找不到任何相关内容,但我能找到的最接近的内容是\parbox

平均能量损失

\documentclass[hidelinks,a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }
\usepackage{mathptmx}  % Times New Roman
\usepackage{setspace}  % Double spacing

\newcommand*\ruleline[1]{\par\noindent\raisebox{.8ex}{\makebox[\linewidth]{\hrulefill\hspace{1ex}\raisebox{-.8ex}{\textsc{#1}}\hspace{1ex}\hrulefill}}}

\setlength{\parindent}{0pt}
\doublespacing

\begin{document}

\ruleline{Questions}

\begin{enumerate}
  \item How would I be able to make a box to surround  \verb!\item! with \LaTeX{}?
  \item It should have an argument for string...
  \item ...and another argument for a colour choice

\ruleline{More Questions}
  \item The box should look something like this
  \item minimum two to three \verb!\item!s high
  \item some stuff
  \item some more stuff
  \item some more stuff

\end{enumerate}

\end{document}

理想输出

在此处输入图片描述

问题

我如何更改我的 MWE 代码来获取理想输出

答案1

根据 David Purton 撰写上一个答案,这里有一个完整的解决方案(带有enumitem包,它提供了一个恢复机制enumerate)。

我在环境外部添加了一个leftmargin1.54 厘米(1 英寸减 1 厘米)的空间,用于对齐产品编号。enumeratemybox

如您所见,对于盒装物品,enumerate环境必须位于mybox环境内部。

\documentclass[hidelinks,a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
 \geometry{
 %a4paper, <-- commented because this is a global option in the documentclass
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage[skins]{tcolorbox}
\usepackage{varwidth}

\makeatletter
\newtcolorbox{mybox}[1][]{
  enhanced,
  colframe=black, colback=white,
  sharp corners,
  boxrule=0.6pt,
  detach title,
  coltitle=black,
  colbacktitle=white,
  fonttitle=\footnotesize,
  overlay={
    \node[rotate=90,
          fill=white,
          font=\kvtcb@fonttitle,
          minimum width=1cm]
          at (frame.west)
      {\begin{varwidth}{\tcbtextheight}
         \centering\tcbtitle\par
       \end{varwidth}};
  },#1}
\makeatother

\newcommand*\ruleline[1]{\par\noindent\raisebox{.8ex}{\makebox[\linewidth]{\hrulefill\hspace{1ex}\raisebox{-.8ex}{\textsc{#1}}\hspace{1ex}\hrulefill}}}

\usepackage{enumitem} % for resuming a list

\begin{document}
    \ruleline{Hello}

    \begin{mybox}[title=Part A]
        \begin{enumerate}[series=g_cntr] % g_cntr: a global counter
            \item How would I be able to make a box to surround  \verb!\item! with \LaTeX{}?
            \item It should have an argument for string... 
            \item ...and another argument for a colour choice and another very very very very pointlessly long string to test the box.
        \end{enumerate}
    \end{mybox}

    \begin{enumerate}[leftmargin=1.54cm,resume=g_cntr] % 1.54cm = 1in - 1cm
        \item ...and another argument for a colour choice
    \end{enumerate}

    \ruleline{The second Hello}

    \begin{mybox}[colframe=red, title=Part B - Very Important]
        \begin{enumerate}[resume=g_cntr]
            \item minimum two to three \verb!\item!s high
            \item some stuff
            \item some more stuff
            \item some more stuff
       \end{enumerate}
    \end{mybox}

    \begin{enumerate}[leftmargin=1.54cm,resume=g_cntr] % 1.54cm = 1in - 1cm
        \item continue
        \item as if there are no boxes
    \end{enumerate}
\end{document}

在此处输入图片描述

答案2

这应该可以让你入门了。我使用了overlaytikz节点将标题放在左边框上。变量宽度由varwidth环境完成。

更新更具体地解决原始问题布局。

我曾经enumitem恢复过编号,但我无法完全自动设置。请参阅enumitem,可以在 \setlist 中放入“series=<name>”吗?\begin{enumerate}[start=1, series=questions]。因此,每当您想要一个以 1 开头的列表时,仍然需要使用它。

我已将框加宽,使其向左边缘突出,足以容纳标题,向右边缘突出,以便框中的文本宽度与普通文本中的文本宽度相同。这是使用以下tcolorbox选项完成的:

enlarge left by=-8mm,
enlarge right by=-2mm,
width=\linewidth+10mm,
left=7mm,
right=2mm,

我还添加了一些代码,before upper使框内的缩进和间距与普通文本更加一致。查看我的问题这里这里

平均能量损失

\documentclass[a4paper,12pt]{article}

\usepackage{xhfill}
\usepackage{enumitem}
\usepackage[skins]{tcolorbox}
\usepackage{varwidth}

\makeatletter
\newtcolorbox{mybox}[1][]{
  enhanced,
  colframe=black, colback=white,
  sharp corners,
  boxrule=0.6pt,
  detach title,
  coltitle=black,
  colbacktitle=white,
  fonttitle=\footnotesize,
  enlarge left by=-8mm,
  enlarge right by=-2mm,
  width=\linewidth+10mm,
  left=7mm,
  right=2mm,
  before upper=\setlength{\parindent}{17.62482pt}\everypar{{\setbox0\lastbox}\@minipagefalse\everypar{}},
  overlay={
    \node[rotate=90,
          fill=tcbcolbacktitle,
          font=\kvtcb@fonttitle,
          minimum width=1cm]
          at (frame.west)
      {\begin{varwidth}{\tcbtextheight}%
         \centering\tcbtitle\par
       \end{varwidth}};
  },#1}
\makeatother

\setlist[enumerate,1]{resume=questions}

\newcommand{\questionheading}[1]{%
  \vskip 2mm
  \noindent\strut\xrfill{0.6pt}\strut\space\textsc{#1}\space\xrfill{0.6pt}\par
  \vskip 2mm}

\begin{document}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.

\questionheading{Questions}

\begin{mybox}[title=Part A]
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
  vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum
  gravida mauris.
  \begin{enumerate}[start=1, series=questions]
    \item How would I be able to make a box to surround  \verb!\item! with \LaTeX{}?
    \item It should have an argument for string...
    \item ...and another argument for a colour choice
  \end{enumerate}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
  vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum
  gravida mauris.
\end{mybox}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.

\questionheading{More Questions}

\begin{enumerate}
  \item The box should look something like this
\end{enumerate}

\begin{mybox}[colframe=red, title=Part B - Some very long text that goes for
  two or three lines]
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
  vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum
  gravida mauris.
  \begin{enumerate}
    \item minimum two to three \verb!\item!s high
    \item some stuff
    \item some more stuff
    \item some more stuff
  \end{enumerate}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
  vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum
  gravida mauris.
\end{mybox}

\end{document}

MWE 输出

相关内容