精确定位 tikzpicture 侧面的文本

精确定位 tikzpicture 侧面的文本

如何将垂直居中的文本放在图表的侧面?

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}   
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}

\begin{description}
\item[Solution]
\begin{minipage}[b]{0.48\textwidth} 
    \begin{tikzpicture}[scale=0.7, baseline={(current bounding box.north)}]
        \draw[step=1cm,color=gray!20] (-4,-4) grid (4,5);
        \draw[->] (-4,0) -- (4.3,0) node[right] {$x$};
        \draw (0,0) node[below right] {$0$};
        \draw[->] (0,-4) -- (0,5.5) node[above] {$y$};
        \foreach \x in { -2, -1,1, 2, 3}
        \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
        \foreach \y in {-2, -1, 1, 3,5}
        \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$}; 
        \clip (-3,-3) rectangle (5,5);
        \draw[scale=1,smooth,very thick, variable=\x,black,domain=-3:1] plot ({\x},{\x});
        \draw[scale=1,smooth,very thick, variable=\x,black,domain=1:3] plot ({\x},{(\x+2});
        \draw[fill=black](1,1) circle(0.7mm);
        \draw[fill=white](1,3) circle(0.7mm);
        \draw[densely dotted] (-1,0)--(-1,-1)--(0,-1);
        \draw[densely dotted] (-2,0)--(-2,-2)--(0,-2);
    \end{tikzpicture}
   \end{minipage}
   \begin{minipage}[]{0.48\textwidth}   
    $\left( -2,-1\right] \in \tau $, but, since $%
    f^{-1}\left( \left( -2,-1\right] \right) =\left( -2,-1\right] \notin \tau_{D}$, it is not 
  continuous.
 \end{minipage}
 \end{description}

 \end{document}

在此处输入图片描述

答案1

在此处输入图片描述

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}   
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
    
%   \begin{description}
\noindent\hspace{-2cm}
        \textbf{ Solution}\\
        \begin{minipage}[]{0.45\textwidth} 
            \begin{tikzpicture}[scale=0.7, baseline={(current bounding box.north)}]
                \draw[step=1cm,color=gray!20] (-4,-4) grid (4,5);
                \draw[->] (-4,0) -- (4.3,0) node[right] {$x$};
                \draw (0,0) node[below right] {$0$};
                \draw[->] (0,-4) -- (0,5.5) node[above] {$y$};
                \foreach \x in { -2, -1,1, 2, 3}
                \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
                \foreach \y in {-2, -1, 1, 3,5}
                \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$}; 
                \clip (-3,-3) rectangle (5,5);
                \draw[scale=1,smooth,very thick, variable=\x,black,domain=-3:1] plot ({\x},{\x});
                \draw[scale=1,smooth,very thick, variable=\x,black,domain=1:3] plot ({\x},{(\x+2});
                \draw[fill=black](1,1) circle(0.7mm);
                \draw[fill=white](1,3) circle(0.7mm);
                \draw[densely dotted] (-1,0)--(-1,-1)--(0,-1);
                \draw[densely dotted] (-2,0)--(-2,-2)--(0,-2);
            \end{tikzpicture}
        \end{minipage}\hfill
        \begin{minipage}[]{0.4\textwidth}   
            $\left( -2,-1\right] \in \tau $, but, since $%
            f^{-1}\left( \left( -2,-1\right] \right) =\left( -2,-1\right] \notin \tau_{D}$, it is not 
            continuous.
        \end{minipage}
%   \end{description}
    
\end{document}
    

答案2

您可以将其添加到tikzpicture。请注意,您预见的边界框宽度有点太大,所以我不得不稍微减小它。

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}   
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}

\begin{description}
\item[Solution]
    \begin{tikzpicture}[scale=0.7, baseline={(current bounding box.north)}]
     \begin{scope}[local bounding box=plot]
        \draw[step=1cm,color=gray!20] (-4,-4) grid (4,5);
        \draw[->] (-4,0) -- (4.3,0) node[right] {$x$};
        \draw (0,0) node[below right] {$0$};
        \draw[->] (0,-4) -- (0,5.5) node[above] {$y$};
        \foreach \x in { -2, -1,1, 2, 3}
        \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
        \foreach \y in {-2, -1, 1, 3,5}
        \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$}; 
        \clip (-3,-3) rectangle (5,5);
        \draw[scale=1,smooth,very thick, variable=\x,black,domain=-3:1] plot ({\x},{\x});
        \draw[scale=1,smooth,very thick, variable=\x,black,domain=1:3] plot ({\x},{(\x+2});
        \draw[fill=black](1,1) circle(0.7mm);
        \draw[fill=white](1,3) circle(0.7mm);
        \draw[densely dotted] (-1,0)--(-1,-1)--(0,-1);
        \draw[densely dotted] (-2,0)--(-2,-2)--(0,-2);
     \end{scope}    
        \path (plot.east) node[right,text width=0.32\textwidth]
        {%
    $\left( -2,-1\right] \in \tau $, but, since $%
    f^{-1}\left( \left( -2,-1\right] \right) =\left( -2,-1\right] \notin \tau_{D}$, it is not 
        };
    \end{tikzpicture}
 \end{description}
 \end{document}

在此处输入图片描述

答案3

  • 您不需要为您的解决方案制作小页面,您只需在makecell图像旁边的表格中添加带有注释的描述(由撰写)。
  • 图表代码基于可接受的回答在你之前的一个问题上,它有更短更干净的代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{amsmath}
\usepackage{makecell}

\begin{document}
    \begin{tikzpicture}[scale=0.7, baseline, % <--- note baseline
         > = Straight Barb,
dot/.style = {circle, draw, fill=#1, minimum size=2mm, inner sep=0pt,
              node contents={}}
                        ]
\draw[step=1cm,color=gray!20] (-3,-3) grid (4,5);
% axis and ticks
\draw[->] (-3,0) -- (4.5,0) node[right] {$x$};
\draw[->] (0,-3) -- (0,5.5) node[above] {$y$};
    \foreach \x in { -2, -1,...,3}
\draw (\x,2pt) -- ++ (0,-4pt) node[fill=white,anchor=north, font=\footnotesize]    {$\x$};
    \foreach \y in { -2, -1,1,3,5}
\draw (2pt,\y) -- ++ (-4pt,0) node[anchor=east]     {$\y$};
% dasheded lines
\draw[densely dotted] (-1,0) |- (0,-1)
                      (-2,0) |- (0,-2);
% function
\draw[thick]    (-3,-3) -- (1,1)  node[dot=white]
                (1,3) node[dot=black] -- (3,5);
    \end{tikzpicture}
\quad
% descriptions
$\makecell[l]{
    (-2,-1] \in \tau, \text{but, since}                   \\
    f^{-1}\bigl((-2,-1] \bigr) = (-2,-1] \notin \tau_{D}, \\
    \text{ it is not continuous.}
            }$
\end{document}

在此处输入图片描述

笔记: 你也makecell可以使用array表格:

$\begin{array}{l}
    (-2,-1] \in \tau, \text{but, since}                   \\
    f^{-1}\bigl((-2,-1] \bigr) = (-2,-1] \notin \tau_{D}, \\
    \text{ it is not continuous.}
 \end{array}$

结果和以前一样。

答案4

\begin{tikzpicture}[scale=0.8]
% Axis
\draw[->] (0,0) -- (10,0) node[below] {$T$};
\draw[->] (0,0) -- (0,10) node[left] {$P$};
% Curves
\draw[thick] (0,8) to [out=0,in=90] (2,6) to [out=-90,in=180] (4,4) to [out=0,in=180] (8,2) node[below] {Líquido};
\draw[thick] (0,8) to [out=-90,in=180] (2,2) node[below] {Sólido};
\draw[thick] (4,4) to [out=90,in=180] (6,6) node[above] {Gas};
\draw[thick] (6,6) -- (10,6) node[right] {Fluido supercrítico};
% Points
\filldraw (0,8) circle (2pt) node[left] {A};
\filldraw (2,6) circle (2pt) node[above left] {B};
\filldraw (4,4) circle (2pt) node[above left] {C};
\filldraw (6,6) circle (2pt) node[above right] {D};
% Labels
\node at (1,7) {Sublimación};
\node at (3,5) {Fusión};
\node at (5,3) {Vaporización};
\node at (7,5) {Punto crítico};
\end{tikzpicture}

相关内容