\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\newtcolorbox{mybox}{%
colback=yellow,
hbox
}
\begin{document}
\begin{mybox}
\begin{tikzpicture}[%
plotmark/.style = {solid, fill, circle, inner sep = 0pt, minimum size = 4pt}]
\node [plotmark,label={below:$A$}] (A) at (0,0) {};
\node [plotmark,label={below:$B$}] (B) at (3,1) {};
\draw[shorten >=-2cm] (A)--(B);
\end{tikzpicture}
\end{mybox}
\end{document}
我遇到了同样的问题(即使没有选择fbox
也会出现同样的问题)。hbox
tcolorbox
答案1
如果你做需要tcolorbox
,您可以使用enhanced
和clip upper
选项解决您的问题。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\newtcolorbox{mybox}{%
enhanced,
colback=yellow,
hbox,
clip upper
}
\begin{document}
\begin{mybox}
\begin{tikzpicture}[plotmark/.style = {solid, fill, circle, inner sep = 0pt, minimum size = 4pt}]
\node [plotmark,label={below:$A$}] (A) at (0,0) {};
\node [plotmark,label={below:$B$}] (B) at (3,1) {};
\draw[shorten >=-2cm] (A)--(B);
\end{tikzpicture}
\end{mybox}
\end{document}
结果:
答案2
我在 TikZ 中制作了这个盒子,因为我看不出您是否真的需要tcolorbox
!?
我把盒子做成了随机尺寸,带有超大的角,这样你就可以看到线正确地保持在里面 - 你可以根据需要进行添加调整。
\documentclass[border = 1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[%
plotmark/.style = {solid, fill, circle, inner sep = 0pt, minimum
size = 4pt}
]
\draw[fill=yellow, rounded corners=1 cm] (-1,-1) rectangle (4,2);
\clip[rounded corners= 1cm] (-1,-1) rectangle (4,2);
\node [plotmark,label={below:$A$}] (A) at (0,0) {};
\node [plotmark,label={below:$B$}] (B) at (3,1) {};
\draw[shorten >=-2cm] (A)--(B);
\end{tikzpicture}
\end{document}
现在这条线还没有接触A
- 可以通过添加outer sep = 0 pt
样式来进行修改plotmark
。