我无法定位一个框,并且不确定为什么会发生这种情况。首先,这是预期的行为。我希望框出现在距离文本 1cm 左侧和 1cm 下方的位置,如下所示:
\documentclass{article}
\usepackage{enumitem}
\usepackage[usenames,table]{xcolor}
\usepackage{tcolorbox}
\begin{document}
Here is some text, and a box should appear 1cm underneath, 1cm from the left:
\vspace{1cm}
\hspace{1cm}
\colorbox{orange}{\LARGE 6-10}
\end{document}
然而,我现在想要在描述列表的标签内实现相同的功能,但发生了非常奇怪的事情。
以下是代码:
\documentclass{article}
\usepackage{enumitem}
\usepackage[usenames,table]{xcolor}
\usepackage{tcolorbox}
\begin{document}
\begin{description}[style=multiline,leftmargin=3cm]
\item[Third item\\
%\vspace{1cm} -- These I rotatively turn on and off
%\hspace{1cm} -- These I rotatively turn on and off
\colorbox{orange}{\LARGE 6-10}]
Here is information. This is a multiline description. We will copy
these lines a few times. Here is information. This is a multiline description.
We will copy these lines a few times. Here is information. This is a multiline
description. We will copy these lines a few times. Here is information. This is
a multiline description. We will copy these lines a few times.Here is
information. This is a multiline description. We will copy these lines a few
time.
\end{description}
\end{document}
这是没有任何 hspace 和 vspace 的样子:
1cm垂直空间(???):
1cm 高度(无任何反应):
1cm 水平空间和 1cm 垂直空间:
我是 LaTeX 初学者,一直在努力定位方框。因此,我对解决方案很感兴趣,但也非常想知道 a)为什么发生了这种情况吗?b)我自己怎样才能发现这一点?
答案1
您需要\hspace*
避免\hspace
在行首丢失空格,并且可以使用以下方法添加垂直空格\\[1cm]
\documentclass{article}
\usepackage{enumitem}
\usepackage[usenames,table]{xcolor}
\usepackage{tcolorbox}
\begin{document}
\begin{description}[style=multiline,leftmargin=3cm]
\item[{Third item\\[1cm]%
\hspace*{1cm}%
\colorbox{orange}{\LARGE 6-10}}]
Here is information. This is a multiline description. We will copy
these lines a few times. Here is information. This is a multiline description.
We will copy these lines a few times. Here is information. This is a multiline
description. We will copy these lines a few times. Here is information. This is
a multiline description. We will copy these lines a few times.Here is
information. This is a multiline description. We will copy these lines a few
time.
\end{description}
\end{document}
答案2
您可以使用白色框1cm X 1cm
作为解决方法:
\item[Third item\\
\textcolor{white}{\rule{1cm}{1cm}}% <--- % needed here
\colorbox{orange}{\LARGE 6-10}]
代码:
\documentclass{article}
\usepackage{enumitem}
\usepackage[usenames,table]{xcolor}
\usepackage{tcolorbox}
\begin{document}
\begin{description}[style=multiline,leftmargin=3cm]
\item[Third item\\
\textcolor{white}{\rule{1cm}{1cm}}% <--- % needed here
\colorbox{orange}{\LARGE 6-10}]
Here is information. This is a multiline description. We will copy
these lines a few times. Here is information. This is a multiline description.
We will copy these lines a few times. Here is information. This is a multiline
description. We will copy these lines a few times. Here is information. This is
a multiline description. We will copy these lines a few times.Here is
information. This is a multiline description. We will copy these lines a few
time.
\end{description}
\end{document}