标注框与对齐环境内容不对齐

标注框与对齐环境内容不对齐

我已经能够split rectangle成功创建。我已经能够使用\tikzmarkcallout盒子。但现在我将两者结合起来,出现了严重问题。

这是我的 MWE

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,decorations}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{calc}
\tikzset
  {
    set frame design/.style={rounded corners=15, 
                             line width=1.4pt, 
                             inner sep=2ex,
                             color=frame_color,
                             text=title_text_color,
                            },
    rectangle split in two/.style={rectangle split, 
                                   rectangle split parts=2, 
                                  },
  }

\colorlet{title_text_color}{blue}
\colorlet{title_bg_color}{yellow!10}
\colorlet{content_text_color}{blue}
\colorlet{content_bg_color}{red!20}
\colorlet{frame_color}{purple}

\newenvironment{myframed}[1]
  {\def\myframedtitle{#1}%%
   \begin{tikzpicture}
     \draw let \p1=($(\linewidth,0)-(1cm,0)$), 
               \p2=(0,0.5\baselineskip)
               in node [ 
                         draw, 
                         anchor=north,
                         set frame design,
                         rectangle split in two,
                         rectangle split part fill={title_bg_color,
                                                    content_bg_color},
                         rectangle split empty part height=\y2
                       ] (this_split_frame) at (0,0) 
               \bgroup 
                \nodepart{second} 
                \begin{minipage}{\x1}
                  \begin{minipage}{0.60\textwidth}\vspace{0pt}
                  \color{title_text_color}
  }
  {               \end{minipage}
                \end{minipage}
             \egroup;
     \node [
            set frame design,
            anchor=north west,
            text=title_text_color
           ] at (this_split_frame.north west) { \bf\large \myframedtitle};
    \end{tikzpicture}
  }

%% setting `inner sep` and `outer sep` helps a little but doesn't correct things
\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node (#1) {};}
%%  \tikz[remember picture,overlay,inner sep=0pt,outer sep=0pt]\node (#1) {};}

\newcommand\mynote[3][]{%
  \begin{tikzpicture}[remember picture,overlay]
  \node[rectangle callout, 
        draw=blue,
        fill=blue!10,
        text width=4cm,
        align=center,
        #1] at #2 {#3};
  \end{tikzpicture}%'
  }

\begin{document}

\begin{myframed}{Case: same denominator}
  Here is some text \tikzmark{a}\par
  Here's some more text \tikzmark{b}
%%  \begin{align*}
%%    \frac{3}{5} + \frac{4}{5} 
%%    & = \tikzmark{a} \frac{3+4}{5}  \\[2ex] %% 
%%    & = \tikzmark{b} \frac{7}{5}   
%%  \end{align*}
\end{myframed}

\mynote[callout relative pointer={(-1,0)}]
       {(a)}
       {Keep the denominator}

\mynote[callout relative pointer={(-1,0)}]
       {(b)}
       {Combine numerators}

\end{document}

在此处输入图片描述

更新

在我看来,问题的一部分在于\tikzmark继承自的设置,\tikzset 如果知道如何根据上下文关闭这些设置就好了。

我可以通过重新定义来改善一些事情\tikzmark,如下所示:

\newcommand\tikzmark[1]{%
  \tikz[remember picture,
        overlay,anchor=center,
        draw=none,
        rectangle split parts=1,
        inner sep=0pt,
        outer sep=0pt,
        rounded corners=0]\node (#1) {};}

callout框的位置仍然不正确,并且定义的节点\tikzmark仍然可见。通过使用

\mynote[callout relative pointer={(-1,0)}]
       {([xshift=0in]a.east)}
       {Keep the denominator}

\mynote[callout relative pointer={(-1,0)}]
       {([yshift=-1in]b)}
       {Combine numerators}

在此处输入图片描述

进一步更新

\tikzmark通过将定义更改为,情况可以有所改善

\newcommand\tikzmark[1]{%
  \tikz[remember picture,
        overlay,
        ]\coordinate (#1) at (0,0) ;
  }

通过使用以下命令,您可以看到坐标位于预期的位置:

\tikz[remember picture,overlay] \draw (a) -- (b) ;

callout我使用s移动了框yshift,以帮助查看这条线的绘制位置:

在此处输入图片描述

所以问题仍然是为什么盒子callout没有指向正确的坐标。

解决方案

问题是我没有正确地引用参考点。如果我改写

\mynote[callout absolute pointer={($(a)+(1.25cm,0)$)}]
       {([xshift=2in]a)}
       {Keep the denominator}

\mynote[callout absolute pointer={($(b)+(1.25cm,0)$)}]
       {([xshift=2in]b)}
       {Combine numerators}

然后我得到了想要的结果:

在此处输入图片描述

答案1

我所做的事情有几个问题。这是我想到的解决方案,但我非常希望有人能做得更好。

首先,我应该\tikzmark根据coordinate零维度的来定义,而不是根据具有维度并将继承其嵌套的node属性的来定义。node

\newcommand\tikzmark[1]{%
  \tikz[remember picture,
        overlay,
        ]\coordinate (#1) at (0,0) ;
  }

指针的第二个问题在于我如何引用它们,我对这个问题仍然有点模糊,但以下代码可以使callout框定位得更好。我应该使用键callout absolute pointer并使用节点修饰符来正确放置标注框:

\mynote[callout absolute pointer={($(a)+(1.25cm,0)$)},anchor=west]
       {([xshift=0.75in]a)}
       {Keep the common denominator and write a new fraction with this common denominator.}

为了让事情进展得更好,我加载了varwidth包。这是最终文件。

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{calc}
\tikzset
  {
    set frame design/.style={rounded corners=15, 
                             line width=1.4pt, 
                             inner sep=2ex,
                             color=frame_color,
                             text=title_text_color,
                            },
    rectangle split in two/.style={rectangle split, 
                                   rectangle split parts=2, 
                                  },
  }

\colorlet{title_text_color}{blue}
\colorlet{title_bg_color}{yellow!10}
\colorlet{content_text_color}{blue}
\colorlet{content_bg_color}{red!20}
\colorlet{frame_color}{purple}

\newsavebox{\mybox}
\newenvironment{myframed}[1]
  {\def\myframedtitle{#1}%%
   \begin{tikzpicture}
     \draw let \p1=($(\textwidth,0)-2*(2ex,0)-2*(1.4pt,0)$), 
               \p2=(0,0.5\baselineskip)
               in node [ 
                         draw, 
                         anchor=north,
                         set frame design,
                         rectangle split in two,
                         rectangle split part fill={title_bg_color,
                                                    content_bg_color},
                         rectangle split empty part height=\y2
                       ] (this_split_frame) at (0,0) 
               \bgroup 
                \nodepart{second} 
                \begin{minipage}{\x1}
                  \begin{minipage}{0.50\linewidth}\vspace{-\abovedisplayskip}
                  \color{title_text_color}
  }
  {               \end{minipage}
                \end{minipage}
             \egroup;
     \node [
            set frame design,
            anchor=north west,
            text=title_text_color
           ] at (this_split_frame.north west) { \bf\large \myframedtitle};
    \end{tikzpicture}
  }

\newcommand\tikzmark[1]{%
  \tikz[remember picture,
        overlay,
        ]\coordinate (#1) at (0,0.75ex) ;
  }


\newlength{\mynotewidth}
\setlength{\mynotewidth}{5cm}
\newcommand\mynote[3][]{%
  \begin{tikzpicture}[remember picture,overlay]
  \node[rectangle callout, 
        fill=blue!10,
        draw=blue,
        #1] at #2 {\begin{varwidth}{\mynotewidth}{#3}\end{varwidth}};
  \end{tikzpicture}%'
  }

\begin{document}

\noindent
\begin{myframed}{Case: same denominator}
  \begin{align*}
    \frac{3}{5} + \frac{4}{5} 
    & = \tikzmark{a} \frac{3+4}{5}  \\[2ex] 
    & = \tikzmark{b} \frac{7}{5}   
  \end{align*}
\end{myframed}

\mynote[callout absolute pointer={($(a)+(1.25cm,0)$)},anchor=west]
       {([xshift=0.75in]a)}
       {Keep the common denominator and write a new fraction with this common denominator.}

\mynote[callout absolute pointer={($(b)+(1.25cm,0)$)},anchor=west]
       {([xshift=0.75in]b)}
       {Combine the numerators}

\end{document}

在此处输入图片描述

相关内容