![如何强制Tikz图片中的延长线留在框内](https://linux22.com/image/377382/%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6Tikz%E5%9B%BE%E7%89%87%E4%B8%AD%E7%9A%84%E5%BB%B6%E9%95%BF%E7%BA%BF%E7%95%99%E5%9C%A8%E6%A1%86%E5%86%85.png)
\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
。