画一个 X 穿过图形

画一个 X 穿过图形

我怎样才能画一条穿过图 2 的线?我原本想画两条穿过该图形的线,但不知道如何识别该图形的 4 个角才能做到这一点

在此处输入图片描述

\documentclass[hidelinks,14pt, letterpaper]{extarticle}
\usepackage{amsmath, amssymb, tikz, multicol}

\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}

\begin{document}

\begin{figure}
    \centering
    \begin{minipage}{0.45\textwidth}
        \centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw 
  (A) -- 
  node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
  node[right] {?} (C) -- 
  node[below] {?} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);

\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
    \end{minipage}\hfill
    \scalebox{1.4}{$\boldsymbol{\Longrightarrow}$}
    \begin{minipage}{0.45\textwidth}
        \centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw 
  (A) -- 
  node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
  node[right] {?} (C) -- 
  node[below] {?} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
    \end{minipage}
\end{figure}

\end{document}

答案1

您可以current bounding box为此使用节点。

\documentclass[hidelinks,14pt, letterpaper]{extarticle}
\usepackage{amsmath, amssymb, tikz, multicol}

\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}

\begin{document}

\begin{figure}
    \centering
    \begin{minipage}{0.45\textwidth}
        \centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw 
  (A) -- 
  node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
  node[right] {?} (C) -- 
  node[below] {?} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);

\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
    \end{minipage}\hfill
    \scalebox{1.4}{$\boldsymbol{\Longrightarrow}$}
    \begin{minipage}{0.45\textwidth}
        \centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw 
  (A) -- 
  node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
  node[right] {?} (C) -- 
  node[below] {?} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
  \draw[red,thick] (current bounding box.north west)
  -- (current bounding box.south east)
  (current bounding box.north east)
  -- (current bounding box.south west);
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
    \end{minipage}
\end{figure}
\end{document}

在此处输入图片描述

另一个选项是定义一个local bounding box,我在这里将其与caption包结合起来,这样更容易相对定位图形和标题。在当前图片中,这不太相关,但一旦你开始绘制两张不同大小的图片,它就会变得相关。

\documentclass[hidelinks,14pt, letterpaper]{extarticle}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{caption}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1.25]
 \begin{scope}[local bounding box=L]
 \coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
 \coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
 \coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
 \draw 
   (A) -- 
   node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
   node[right] {?} (C) -- 
   node[below] {?} 
   (A);
 \draw 
   (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
 \end{scope}
 \node[anchor=north,text width=6cm,align=center] at (L.south) {\captionof{figure}{Caption.}};
 \begin{scope}[xshift=6cm,local bounding box=R]
 \coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
 \coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
 \coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
 \draw 
   (A) -- 
   node[midway,above left=0pt] {$\sqrt{1+x^2}$} (B) --
   node[right] {?} (C) -- 
   node[below] {?} 
   (A);
 \draw 
   (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
 \end{scope}
 \path (L) -- (R) node[midway,scale=1.4]{$\boldsymbol{\Longrightarrow}$};
 \draw[red,thick] (R.north west)  -- (R.south east)
  (R.north east)  -- (R.south west);
 \node[anchor=north,text width=6cm,align=center] at (R.south) {\captionof{figure}{Caption.}};
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

一般而言,遗嘱local bounding box允许您划掉其中的内容。

相关内容