Tikz 图片位置

Tikz 图片位置

我想把这个图与 1 相对,我该怎么做?实际上我怎样才能根据需要更改图片的位置?

 \documentclass[twocolumn,10pt]{article}
    \usepackage{pgf,tikz,pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{mathrsfs}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    
    
    
    
    \begin{document}
    \definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
    \definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
    \textbf{1)}\newline
    \begin{tikzpicture}[scale=0.8, line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \clip(-5.003269918455611,-3.3529348860915125) rectangle (10.415703512539228,5.13457342454785);
    \fill[line width=2.pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] (-1.16,2.85) -- (-3.82,-1.57) -- (3.56,-1.55) -- cycle;
    \draw [line width=2.pt,color=rvwvcq] (-1.16,2.85)-- (-3.82,-1.57);
    \draw [line width=2.pt,color=rvwvcq] (-3.82,-1.57)-- (3.56,-1.55);
    \draw [line width=2.pt,color=rvwvcq] (3.56,-1.55)-- (-1.16,2.85);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-2.7200080786122416,-1.56701899208296);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-0.9600210043918271,-1.562249379415696);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (1.1000722668585952,-1.5566664708215214);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (2.4001169195517105,-1.5531433145811606);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (0.2994927758991701,1.4894558868736556);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (1.60355056870581,0.27380879188441476);
    \begin{scriptsize}
    \draw [fill=rvwvcq] (-1.16,2.85) circle (2.5pt);
    \draw [fill=rvwvcq] (-3.82,-1.57) circle (2.5pt);
    \draw [fill=rvwvcq] (3.56,-1.55) circle (2.5pt);
    \draw [fill=rvwvcq] (-2.7200080786122416,-1.56701899208296) circle (2.5pt);
    \draw [fill=rvwvcq] (-0.9600210043918271,-1.562249379415696) circle (2.5pt);
    \draw [fill=rvwvcq] (1.1000722668585952,-1.5566664708215214) circle (2.5pt);
    \draw [fill=rvwvcq] (2.4001169195517105,-1.5531433145811606) circle (2.5pt);
    \draw [fill=rvwvcq] (0.2994927758991701,1.4894558868736556) circle (2.5pt);
    \draw [fill=rvwvcq] (1.60355056870581,0.27380879188441476) circle (2.5pt);
    \end{scriptsize}
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

我想喜欢这个

在此处输入图片描述 我想要那样的

答案1

这里真正的问题是图表的边界框太大。添加

\draw (current bounding box.south east) rectangle (current bounding box.north west);

\end{tikzpicture}在沿着边界框绘制框架之前,你会看到这个:

在此处输入图片描述

这是由 引起的\clip,因此删除该行,您会得到以下结果:

在此处输入图片描述

如果您希望它稍微高一点,如您的图片所示,删除\newline并添加

baseline={([yshift=-\baselineskip]current bounding box.north)}

到的选项tikzpicture。无需额外的\tikz

最后,您要制作列表吗?如果是,我建议使用列表环境,您可以使用包的功能enumitem自定义列表的外观,如下例所示:

\documentclass[twocolumn,10pt]{article}
\usepackage{enumitem} % added
\usepackage{tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\begin{document}
\definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
\definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
\begin{enumerate}[label=\textbf{\arabic*)}]
\item \begin{tikzpicture}[scale=0.8, line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm, baseline=(current bounding box.south), baseline={([yshift=-\baselineskip]current bounding box.north)}]
%  \clip(-5.003269918455611,-3.3529348860915125) rectangle (10.415703512539228,5.13457342454785); %% remove this line
\fill[line width=2.pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] (-1.16,2.85) -- (-3.82,-1.57) -- (3.56,-1.55) -- cycle;
\draw [line width=2.pt,color=rvwvcq] (-1.16,2.85)-- (-3.82,-1.57);
\draw [line width=2.pt,color=rvwvcq] (-3.82,-1.57)-- (3.56,-1.55);
\draw [line width=2.pt,color=rvwvcq] (3.56,-1.55)-- (-1.16,2.85);
\draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-2.7200080786122416,-1.56701899208296);
\draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-0.9600210043918271,-1.562249379415696);
\draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (1.1000722668585952,-1.5566664708215214);
\draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (2.4001169195517105,-1.5531433145811606);
\draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (0.2994927758991701,1.4894558868736556);
\draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (1.60355056870581,0.27380879188441476);
\begin{scriptsize}
\draw [fill=rvwvcq] (-1.16,2.85) circle (2.5pt);
\draw [fill=rvwvcq] (-3.82,-1.57) circle (2.5pt);
\draw [fill=rvwvcq] (3.56,-1.55) circle (2.5pt);
\draw [fill=rvwvcq] (-2.7200080786122416,-1.56701899208296) circle (2.5pt);
\draw [fill=rvwvcq] (-0.9600210043918271,-1.562249379415696) circle (2.5pt);
\draw [fill=rvwvcq] (1.1000722668585952,-1.5566664708215214) circle (2.5pt);
\draw [fill=rvwvcq] (2.4001169195517105,-1.5531433145811606) circle (2.5pt);
\draw [fill=rvwvcq] (0.2994927758991701,1.4894558868736556) circle (2.5pt);
\draw [fill=rvwvcq] (1.60355056870581,0.27380879188441476) circle (2.5pt);
\end{scriptsize}

%\draw (current bounding box.south east) rectangle (current bounding box.north west); % to indicate the bounding box of the diagram
\end{tikzpicture}
\end{enumerate}
\end{document}

答案2

剪辑操作扩大了图像的边界框,通过移除它,它仅仅框住了三角形。

1)写在图像代码之前,我用操作来定位它node

\node[below right] at (current bounding box.north west) {{1)}};

截屏

\documentclass[twocolumn,10pt]{article}
    \usepackage{pgf,tikz,pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{mathrsfs}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    
    
    
    
    \begin{document}
    \definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
    \definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
%    \textbf{1)}\newline
    \begin{tikzpicture}[scale=0.8, line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
%    \clip(-5.003269918455611,-3.3529348860915125) rectangle (10.415703512539228,5.13457342454785);
    \fill[line width=2.pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] (-1.16,2.85) -- (-3.82,-1.57) -- (3.56,-1.55) -- cycle;
    \draw [line width=2.pt,color=rvwvcq] (-1.16,2.85)-- (-3.82,-1.57);
    \draw [line width=2.pt,color=rvwvcq] (-3.82,-1.57)-- (3.56,-1.55);
    \draw [line width=2.pt,color=rvwvcq] (3.56,-1.55)-- (-1.16,2.85);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-2.7200080786122416,-1.56701899208296);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-0.9600210043918271,-1.562249379415696);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (1.1000722668585952,-1.5566664708215214);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (2.4001169195517105,-1.5531433145811606);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (0.2994927758991701,1.4894558868736556);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (1.60355056870581,0.27380879188441476);
    \begin{scriptsize}
    \draw [fill=rvwvcq] (-1.16,2.85) circle (2.5pt);
    \draw [fill=rvwvcq] (-3.82,-1.57) circle (2.5pt);
    \draw [fill=rvwvcq] (3.56,-1.55) circle (2.5pt);
    \draw [fill=rvwvcq] (-2.7200080786122416,-1.56701899208296) circle (2.5pt);
    \draw [fill=rvwvcq] (-0.9600210043918271,-1.562249379415696) circle (2.5pt);
    \draw [fill=rvwvcq] (1.1000722668585952,-1.5566664708215214) circle (2.5pt);
    \draw [fill=rvwvcq] (2.4001169195517105,-1.5531433145811606) circle (2.5pt);
    \draw [fill=rvwvcq] (0.2994927758991701,1.4894558868736556) circle (2.5pt);
    \draw [fill=rvwvcq] (1.60355056870581,0.27380879188441476) circle (2.5pt);
    \end{scriptsize}

    \node[below right] at (current bounding box.north west) {{1)}};
    \end{tikzpicture}
    \end{document}

答案3

在代码中添加以下行

\tikz[baseline={([yshift=-1.2cm]current bounding box.west)}]{}

在此处输入图片描述

\documentclass[twocolumn,10pt]{article}
    \usepackage{pgf,tikz,pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{mathrsfs}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    
    \begin{document}
    \definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
    \definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
    \textbf{1)}\tikz[baseline={([yshift=-1.2cm]current bounding box.west)}]{
    \begin{tikzpicture}[scale=0.8, line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \clip(-5.003269918455611,-3.3529348860915125) rectangle (10.415703512539228,5.13457342454785);
    \fill[line width=2.pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] (-1.16,2.85) -- (-3.82,-1.57) -- (3.56,-1.55) -- cycle;
    \draw [line width=2.pt,color=rvwvcq] (-1.16,2.85)-- (-3.82,-1.57);
    \draw [line width=2.pt,color=rvwvcq] (-3.82,-1.57)-- (3.56,-1.55);
    \draw [line width=2.pt,color=rvwvcq] (3.56,-1.55)-- (-1.16,2.85);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-2.7200080786122416,-1.56701899208296);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-0.9600210043918271,-1.562249379415696);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (1.1000722668585952,-1.5566664708215214);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (2.4001169195517105,-1.5531433145811606);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (0.2994927758991701,1.4894558868736556);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (1.60355056870581,0.27380879188441476);
    \end{tikzpicture}}
    \end{document}

编辑-为了适应手绘草图和 OP 评论的变化

要使用, xshift您需要使用overlay选项——在代码中的\begin{tikzpicture}选项之后添加以下行

remember picture, 
overlay, 
baseline={(current bounding box.base)}, 
yshift=-2cm, 
xshift=4cm,

输出 -

在此处输入图片描述

平均能量损失

\documentclass[twocolumn,10pt]{article}
    \usepackage{pgf,tikz,pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{mathrsfs}
    \usetikzlibrary{arrows, positioning, calc}
    \pagestyle{empty}
    
    
    
    
    \begin{document}
    \definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
    \definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
    \textbf{1)}{
    \begin{tikzpicture}[remember picture, 
                        overlay, 
                        baseline={(current bounding box.base)}, 
                        yshift=-2cm, 
                        xshift=4cm, 
                        scale=0.8, 
                        line cap=round,
                        line join=round,
                        >=triangle 45,
                        x=1.0cm,
                        y=1.0cm,]
    \clip(-5.003269918455611,-3.3529348860915125) rectangle (10.415703512539228,5.13457342454785);
    \fill[line width=2.pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] (-1.16,2.85) -- (-3.82,-1.57) -- (3.56,-1.55) -- cycle;
    \draw [line width=2.pt,color=rvwvcq] (-1.16,2.85)-- (-3.82,-1.57);
    \draw [line width=2.pt,color=rvwvcq] (-3.82,-1.57)-- (3.56,-1.55);
    \draw [line width=2.pt,color=rvwvcq] (3.56,-1.55)-- (-1.16,2.85);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-2.7200080786122416,-1.56701899208296);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (-0.9600210043918271,-1.562249379415696);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (1.1000722668585952,-1.5566664708215214);
    \draw [line width=2.pt,color=wrwrwr] (-1.16,2.85)-- (2.4001169195517105,-1.5531433145811606);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (0.2994927758991701,1.4894558868736556);
    \draw [line width=2.pt,color=wrwrwr] (-3.82,-1.57)-- (1.60355056870581,0.27380879188441476);
    \begin{scriptsize}
    \draw [fill=rvwvcq] (-1.16,2.85) circle (2.5pt);
    \draw [fill=rvwvcq] (-3.82,-1.57) circle (2.5pt);
    \draw [fill=rvwvcq] (3.56,-1.55) circle (2.5pt);
    \draw [fill=rvwvcq] (-2.7200080786122416,-1.56701899208296) circle (2.5pt);
    \draw [fill=rvwvcq] (-0.9600210043918271,-1.562249379415696) circle (2.5pt);
    \draw [fill=rvwvcq] (1.1000722668585952,-1.5566664708215214) circle (2.5pt);
    \draw [fill=rvwvcq] (2.4001169195517105,-1.5531433145811606) circle (2.5pt);
    \draw [fill=rvwvcq] (0.2994927758991701,1.4894558868736556) circle (2.5pt);
    \draw [fill=rvwvcq] (1.60355056870581,0.27380879188441476) circle (2.5pt);
    \end{scriptsize}
    \end{tikzpicture}}
    \end{document}

虽然@TorbjørnT. 已经正确地提出了这个clip因素,但是当我运行代码时,我没有发现任何错误——你可以尝试使用和不使用代码clip来查看哪种方法适合你

相关内容