我正在尝试绘制如下内容:
但随着我的关注(请注意,我已经厌倦了tcolorbox
)
代码 :
\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage[margin=1.5cm]{geometry}
\tcbset{
lemmastyle/.style={enhanced, colback=white, colframe=black, arc=0pt,
fonttitle=\bfseries, description color=Maroon,
colbacktitle=white, coltitle=black,
top=\tcboxedtitleheight,
boxed title style={arc=0pt},
attach boxed title to top left={yshift=-\tcboxedtitleheight/1,
}%
},
}
\newtcbtheorem{myLemma1}{Question :}{lemmastyle}{thm}
\usepackage{pifont}
\usepackage{fancybox}
\begin{document}
\begin{tcolorbox}[width=\textwidth, enhanced, valign=center, colback=white, colframe=black, sharp corners, shadow={0pt}{0pt}{0mm}{black},boxrule=0.5pt]
\textbf{Question 1~: Area of the region bounded by the curves $y=x^2+2, y=-x, x=0$ and $x=1$ is}
\[ \dfrac{7}{10} \]
\end{tcolorbox}
\begin{tcolorbox}[width=\textwidth, enhanced, valign=center, colback=white, colframe=black, sharp corners, shadow={0pt}{0pt}{0mm}{black},boxrule=0.5pt]
\textbf{Question 2~:}
\end{tcolorbox}
\begin{myLemma1}{}{}
\textbf{ Area of the region bounded by the curves $y=x^2+2, y=-x, x=0$ and $x=1$ is \[ \dfrac{7}{10}\] }
\end{myLemma1}
\end{document}
我懂了
输出:
- 有人可以告诉我如何设置
tcolorbox
环境来获得我想要的盒子吗?
答案1
您可以做类似的事(但请注意不要在开始处添加 \par,因为这将消除 hangindent 的效果):
\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[margin=1.5cm]{geometry}
\tcbset{
lemmastyle/.style={enhanced, colback=white, colframe=black, arc=0pt,
fonttitle=\bfseries, description color=Maroon,
colbacktitle=white, coltitle=black,
top=\tcboxedtitleheight,
boxed title style={arc=0pt},
before title=\strut,
attach boxed title to top left={yshift=-\tcboxedtitleheight/1},
before upper={\vspace{\dimexpr-\tcboxedtitleheight+\dp\strutbox-0.8pt}\par\hangindent\tcboxedtitlewidth\hangafter-2},
},
}
\newtcbtheorem{myLemma1}{Question :}{lemmastyle}{thm}
\begin{document}
\begin{myLemma1}{}{}
\lipsum*[1]
\end{myLemma1}
\end{document}
答案2
警告:前方有可怕的黑客攻击 ;-)
很难对齐运行的文本和附加的标题框——也许tcolorbox
手册中有一些选项,但我没有找到。
由于附加的标题框本身是一个tcolorbox
,因此对此的大多数(所有?)设置都可以按照与外部框相同的方式完成。
然而,我使用了单独的\newtcolorbox
——它不再是了tcbtheorem
,以提供更多的灵活性(使用的xparse
工具tcolorbox
将进一步改善这一点)
\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage[margin=1.5cm]{geometry}
\newtcolorbox[auto counter]{myinternallemma}[2][]{%
enhanced,
title={\phantom{Some}},
detach title,
attach title to upper={\hskip0.2\textwidth},
description color=Maroon,
top=-5pt,
colbacktitle=white, coltitle=black,
boxed title style={%
enhanced,arc=0pt,
bottomtitle=1pt,
boxrule=1pt,
coltitle=black,
lowerbox=ignored,
size=normal,
sharp corners,
width={0.1\textwidth},
fonttitle={\bfseries},
title={Question \thetcbcounter},
attach title to upper={},
box align=bottom,
},%
attach boxed title to top left={%
yshift=-\tcboxedtitleheight,
},
#1
}
\usepackage{blindtext}
\usepackage{pifont}
\usepackage{fancybox}
\begin{document}
\begin{myinternallemma}{}
\textbf{ Area of the region bounded by the curves $y=x^2+2, y=-x, x=0$ and $x=1$ is \[ \dfrac{7}{10}\]} \blindtext
\end{myinternallemma}
\end{document}