如何正确裁剪/剪切 Tikz 图像的部分内容

如何正确裁剪/剪切 Tikz 图像的部分内容

我得到了以下图像:

在此处输入图片描述

我想像这样剪切它,但没有填充白色的矩形,因为它们在实际图片和文本之间留下“空白”空间。

在此处输入图片描述

已经有答案了,使用 \clip。以下是编辑后的代码:

\documentclass[leqno,10pt]{extarticle}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
    Illum beatae soluta aliquid beatae velit et. Sit minus alias unde et enim reprehenderit quis odit. Iusto saepe et iure animi. Laborum at voluptas doloremque tempore et ut ullam consectetur.

    \begin{tikzpicture}
        \clip (-2,-2.7) rectangle (9.5,2.7);
        \draw[-] (-2, 0) -- (9.3, 0);
        \draw[->, line width=0.3mm] (9.2999, 0) -- (9.3, 0);
        \coordinate[label=below left:\small$C$] (C) at (-0.863, 0); \fill (C) circle (1pt);
        \coordinate[label=below right:\small$A$] (A) at (8.137, 0); \fill (A) circle (1pt);
        \coordinate[label=above:\small$B$] (B) at (3.637, 4.5); \fill (B) circle (1pt);
        \coordinate[label=below:\small$D$] (D) at (3.637, -4.5); \fill (D) circle (1pt);
        \draw[-] (3.637, 4.5) -- (3.637, -4.5);

        \coordinate[label=below right:\small$A_1$] (A1) at (5.887, 0); \fill (A1) circle (1pt);
        \coordinate[label=below right:\small$A_2$] (A2) at (4.762, 0); \fill (A2) circle (1pt);

        \coordinate[label=above right:\small$B_1$] (B1) at (3.637, 2.25); \fill (B1) circle (1pt);
        \coordinate[label=above right:\small$B_2$] (B2) at (3.637, 1.125); \fill (B2) circle (1pt);

        \coordinate[label=below left:\small$D_1$] (D1) at (3.637, -2.25); \fill (D1) circle (1pt);
        \coordinate[label=below left:\small$D_2$] (D2) at (3.637, -1.125); \fill (D2) circle (1pt);

        \coordinate[label=below left:\small$C_1$] (C1) at (1.387, 0); \fill (C1) circle (1pt);
        \coordinate[label=below left:\small$C_2$] (C2) at (2.512, 0); \fill (C2) circle (1pt);

        \draw[-] (A) -- (B) -- (C) -- (D) -- (A1) -- (B1) -- (C1) -- (D1) -- (A2) -- (B2) -- (C2) -- (D2) -- (4.1995, 0) -- (3.637, 0.5625) -- (3.076, 0) -- (3.637, -0.5625) -- (3.9182, 0) -- (3.637, 0.28125) -- (3.3565, 0) -- (3.637, -0.28125) -- (3.7776, 0) -- (3.637, 0.140625) -- (3.49675, 0) -- (3.637, -0.140625);
        \node[fill=white,inner sep=1.5mm,outer sep=1.5mm] at (3.637,-0.25)
        \coordinate[label=below:\small$L$] (L) at (3.637,0); \fill (L) circle (1pt);

        \draw[thick, pattern=dots] (3.637,0) circle [radius=1.9cm];
\end{tikzpicture}
    
    Omnis quia sint iste adipisci quis laudantium facere nostrum. Inventore non reiciendis eius nulla voluptatem ut pariatur. Eum aliquid eos est sed similique saepe. Voluptas qui dolor saepe aut aut delectus.

\end{document}

答案1

您可以使用剪辑来实现所需的效果。您可以在 TikZ 的官方手册中查找。在这种情况下,只需在 tikzpicture 的开头添加一行类似这样的内容:

\clip (-2,-2) rectangle (9.5,5);

这将确保 TikZ 在该点之后绘制的所有内容只有在剪切路径内才可见(在本例中为矩形)。

顺便说一句:您提供的代码包含一些小的语法错误。

相关内容