在 Tikz 中,有没有办法让 Tikz 图像“准确地”从页面最左边的位置开始?

在 Tikz 中,有没有办法让 Tikz 图像“准确地”从页面最左边的位置开始?

我制作了一个 Tikz 图像,想要用作文档中的某种图标,但是当我尝试将其移至文档的左上角时,我最初发现图像的边界框太大,无法向左移动,然后在对 tikzimage 进行一些剪辑实验后,我发现每当我尝试将图像移至文本通常开始位置的左侧时,图像就会在开头被裁剪,并且只会在标记文本通常在页面中开始位置的线之后绘制。

这有点奇怪,因为一开始我的图像太靠左了,实际上被绘制到了页面的最右边,所以如果它在页面上有某种限制框,它是否也会裁剪右侧的图像?

有没有什么办法可以解决这个问题?

如上所述,我应该提供更具体的信息,所以这就是我正在使用的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}[y=28pt, x=28pt,scale =0.5,yscale=-1.1, xscale=1.2]
\draw[help lines,step=8pt] (-6,-1) grid (18,11);
 \clip (-6,-1) rectangle (30,12);
 \path[fill=black ,xshift = -12cm, rotate=-12] (1.93,2.85) to [curve  
 through ={(4.09,2.77)..
 (3.16,0.15)..(0.45,1.68)..(2.37,6.57)..(8.41,7.82)..(12.30,8.08)}]
 (13.36,8.6) .. controls (14.45,8) and (15.50,7.8) .. (19.08,7.96) to
 [curve  through ={(23.36,8.97)..(25.39,10.67)}] (25.22,12.77) 
 .. controls (24.22,9.9) and (21.65,10.45)..(21.09,12.27) to [curve
 through ={(23.46,15.72)..(27.28,12.86)..(25.40,8.13)..(21.72,6.40)..
 (16.44,5.93)..(15.3,5.79)}] (14.49,5.31) .. controls (14.18,5.5) and 
 (14,5.67)..(13.3,5.82) to [curve  through ={(12.4,5.92)..(8.55,5.89)..
 (5.9,5.75)..(2.01,4.06)}] (1.93,2.85) ;


\end{tikzpicture}


\end{document}

下面是一张图来表达我的意思:

在此处输入图片描述

答案1

xshift使用和移动图片yshift到角落:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}

\begin{tikzpicture}[remember picture, overlay,y=28pt, x=28pt,scale =0.5,yscale=-1.1, xscale=1.2,xshift=-2.7cm,yshift=-7.8cm]
\draw[help lines,step=8pt] (-6,-1) grid (18,11);
 \clip (-6,-1) rectangle (30,12);
 \path[fill=black ,xshift = -12cm, rotate=-12] (1.93,2.85) to [curve  
 through ={(4.09,2.77)..
 (3.16,0.15)..(0.45,1.68)..(2.37,6.57)..(8.41,7.82)..(12.30,8.08)}]
 (13.36,8.6) .. controls (14.45,8) and (15.50,7.8) .. (19.08,7.96) to
 [curve  through ={(23.36,8.97)..(25.39,10.67)}] (25.22,12.77) 
 .. controls (24.22,9.9) and (21.65,10.45)..(21.09,12.27) to [curve
 through ={(23.46,15.72)..(27.28,12.86)..(25.40,8.13)..(21.72,6.40)..
 (16.44,5.93)..(15.3,5.79)}] (14.49,5.31) .. controls (14.18,5.5) and 
 (14,5.67)..(13.3,5.82) to [curve  through ={(12.4,5.92)..(8.55,5.89)..
 (5.9,5.75)..(2.01,4.06)}] (1.93,2.85) ;
\end{tikzpicture}


\end{document}

答案2

让我将我的评论转化为答案:

  • 对于图像定位使用tikzpicture选项remember picture,overlay
  • 用于确定图像大小(仅用于)scale=..., transform shape
  • 对于网格使用节点样式,其中包含:

    path picture={
    \draw[#1,step=#2] (\ppbb.south west) grid (\ppbb.north east);                                  
                  }
    

    其中选项#1#2分别确定网格的线条粗细和颜色以及步长,\ppbb是缩写path picture bounding box

  • 使用相对坐标重新绘制图像。通过此功能可以定位绘制的图像而无需使用任何调整xshiftyshift

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{hobby,positioning}
    \newcommand\coo[1]{coordinate (#1)}             % <---
    \newcommand\ppbb{path picture bounding box}     % <---
    
    \begin{document}
    \begin{tikzpicture}[remember picture,overlay,
                        scale=0.2, transform shape, % <--- determine size
    box/.style args = {#1/#2}{draw,#1,
                            minimum width=300mm, minimum height=200mm,
                            anchor=north west, inner sep=0,
                            path picture={
                            \draw[#1,step=#2] (\ppbb.south west) grid (\ppbb.north east);
                                        }
                                },
    box/.default = {ultra thin, gray}/10 mm
                            ]
    \node (s) [box] at (current page.north west) {};
    \path (s.west)  % the starting coordinate forf drawing the image
        -| ++ ( 3.2,-4.8) \coo{a1} -| ++ ( 2.1,-0.1) \coo{a2} |- ++ (-0.9,-2.6) \coo{a3}
        -| ++ (-2.7, 1.5) \coo{a4} |- ++ ( 1.9, 4.9) \coo{a5} |- ++ ( 6.0, 1.2)\coo{a6}
        -| ++ ( 3.9, 0.3) \coo{a7} |- ++ ( 1.1, 0.5) \coo{a8}
    %
        |- ++ ( 1.1,-0.5) \coo{a9}  -| ++ ( 1.5,-0.2) \coo{a10} -| ++ ( 3.2, 0.1) \coo{a11}
        -| ++ ( 4.2, 1.0) \coo{a12} -| ++ ( 2.0, 1.5) \coo{a13} -| ++ (-0.2, 2.3) \coo{a14}
    %
        -| ++ (-0.8,-1.4) \coo{a15} -- ++ (-2.8, 0.0) \coo{a16} -- ++ ( 0.0, 3.0) \coo{a17}
        |- ++ ( 1.9, 1.4) \coo{a18} -| ++ ( 3.8,-2.9) \coo{a19} |- ++ (-1.9,-4.7) \coo{a20}
        |- ++ (-3.7,-1.7) \coo{a21} |- ++ (-5.2,-0.5) \coo{a22} |- ++ (-1.2,-0.2) \coo{a23}
        |- ++ (-0.8,-0.4) \coo{a24}
    %
        |- ++ (-1.1, 0.5) \coo{a25} |- ++ (-1.2, 0.1) \coo{a26} -- ++ (-3.3,-0.0) \coo{a27}
        |- ++ (-5.4,-0.6) \coo{a28} |- ++ (-1.5,-1.2) \coo{a29};
    \fill[red]
        (a1)  to [curve through={(a2) ..(a3) ..(a4) ..(a5) ..(a6)..(a7)}] (a8) --
        (a8)  to [curve through={(a9) ..(a10)..(a11)..(a12)..(a13)}] (a14) --
        (a14) to [curve through={(a15)..(a16)..(a17)..(a18)..(a19)..
                                 (a20)..(a21)..(a22)..(a23)}] (a24) --
        (a24) to [curve through={(a25)..(a26)..(a27)..(a28)..(a29)}] cycle ;
    \end{tikzpicture}
    \end{document}
    

scale=0.2step=10mm

在此处输入图片描述

scale=0.1step=10mm

在此处输入图片描述

scale=0.1step=15mm

在此处输入图片描述

相关内容