3

This post is building from the post found here developed by Gonzalo Medina. How to get the same equation to behave correctly on two different pages? In my code, the under braces do not fall in the correct position.

Here is my code:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,decorations.pathreplacing}
\usepackage{lipsum}

\begin{document}

\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{starta}P_{s~av}\tikzmark{enda}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startb}\omega_{o}W_{e}\tikzmark{endb}}%
  + \dfrac{1}{\tikzmark{startc}Q_{unl}\tikzmark{endc}}+\dfrac{P_{sig}}{\tikzmark{startd}\omega_{o}W_{e}\tikzmark{endd}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{starte}\omega_{m}\tikzmark{ende}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\foreach \Value/\Length/\Text in {%
  a/15pt/{Phase\\perturbation},%
  b/40pt/{Input power\\over\\reactive power},%
  c/20pt/{Resonator $Q$},%
  d/40pt/{Signal power\\over\\reactive power},%
  e/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\lipsum[1-4]


\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{starta}P_{s~av}\tikzmark{enda}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startb}\omega_{o}W_{e}\tikzmark{endb}}%
  + \dfrac{1}{\tikzmark{startc}Q_{unl}\tikzmark{endc}}+\dfrac{P_{sig}}{\tikzmark{startd}\omega_{o}W_{e}\tikzmark{endd}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{starte}\omega_{m}\tikzmark{ende}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\foreach \Value/\Length/\Text in {%
  a/15pt/{Phase\\perturbation},%
  b/40pt/{Input power\\over\\reactive power},%
  c/20pt/{Resonator $Q$},%
  d/40pt/{Signal power\\over\\reactive power},%
  e/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\end{document}
Joe
  • 9,080

2 Answers2

4

It's a bit unclear from your question where the correct position should be, but I assume you want text pointing to underbraces in the first equation as well. This is not happening in your example because you identify everything using the same names both times. As a result, start\value and end\value are overwritten in equation two, and you only get text pointing to those underbraces. Changing the labels will fix this.

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,decorations.pathreplacing}
\usepackage{lipsum}

\begin{document}

\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{starta}P_{s~av}\tikzmark{enda}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startb}\omega_{o}W_{e}\tikzmark{endb}}%
  + \dfrac{1}{\tikzmark{startc}Q_{unl}\tikzmark{endc}}+\dfrac{P_{sig}}{\tikzmark{startd}\omega_{o}W_{e}\tikzmark{endd}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{starte}\omega_{m}\tikzmark{ende}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\foreach \Value/\Length/\Text in {%
  a/15pt/{Phase\\perturbation},%
  b/40pt/{Input power\\over\\reactive power},%
  c/20pt/{Resonator $Q$},%
  d/40pt/{Signal power\\over\\reactive power},%
  e/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\vspace{3cm}
\lipsum[1-3]


\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{startf}P_{s~av}\tikzmark{endf}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startg}\omega_{o}W_{e}\tikzmark{endg}}%
  + \dfrac{1}{\tikzmark{starth}Q_{unl}\tikzmark{endh}}+\dfrac{P_{sig}}{\tikzmark{starti}\omega_{o}W_{e}\tikzmark{endi}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{startj}\omega_{m}\tikzmark{endj}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\foreach \Value/\Length/\Text in {%
  f/15pt/{Phase\\perturbation},%
  g/40pt/{Input power\\over\\reactive power},%
  h/20pt/{Resonator $Q$},%
  i/40pt/{Signal power\\over\\reactive power},%
  j/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\end{document}

enter image description here

erik
  • 12,673
  • THANK YOU for your solution. I did want the text pointing to underbraces in the first equation as well. Your solution works perfectly! – Joe Oct 02 '15 at 19:45
  • @Joe You're welcome. My initial comment about compiling twice was a knee-jerk response, but when I took a look at the code I saw what you were trying to do. – erik Oct 02 '15 at 19:48
4

How to get the same equation to behave correctly on two different pages?

The book class defaults to twoside typsetting. So, in two different pages the margins are different and your labels need to be corrected accordingly. Using the xshift value of :

xshift=\dimexpr-\leftmargin-\oddsidemargin+\marginparsep 

would compensate for this in an odd page.

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,decorations.pathreplacing}
\usepackage{lipsum}

\begin{document}

\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{starta}P_{s~av}\tikzmark{enda}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startb}\omega_{o}W_{e}\tikzmark{endb}}%
  + \dfrac{1}{\tikzmark{startc}Q_{unl}\tikzmark{endc}}+\dfrac{P_{sig}}{\tikzmark{startd}\omega_{o}W_{e}\tikzmark{endd}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{starte}\omega_{m}\tikzmark{ende}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay,xshift=\dimexpr-\leftmargin-\oddsidemargin+\marginparsep]
\foreach \Value/\Length/\Text in {%
  a/15pt/{Phase\\perturbation},%
  b/40pt/{Input power\\over\\reactive power},%
  c/20pt/{Resonator $Q$},%
  d/40pt/{Signal power\\over\\reactive power},%
  e/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\vspace{3cm}
\lipsum[1-4]

\newpage
\begin{equation}
  L_{\omega_{m}}=\frac{1}{8}\dfrac{FkT}{\tikzmark{starta}P_{s~av}\tikzmark{enda}}\dfrac{\omega_{o}^{2}}{\omega_{m}^{2}}\left(\dfrac{P_{in}}{\tikzmark{startb}\omega_{o}W_{e}\tikzmark{endb}}%
  + \dfrac{1}{\tikzmark{startc}Q_{unl}\tikzmark{endc}}+\dfrac{P_{sig}}{\tikzmark{startd}\omega_{o}W_{e}\tikzmark{endd}} \right)^{2} \left(1 + \dfrac{\omega_{c}}{\tikzmark{starte}\omega_{m}\tikzmark{ende}} \right)
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\foreach \Value/\Length/\Text in {%
  a/15pt/{Phase\\perturbation},%
  b/40pt/{Input power\\over\\reactive power},%
  c/20pt/{Resonator $Q$},%
  d/40pt/{Signal power\\over\\reactive power},%
  e/20pt/{Flicker\\effect}%
  }
{
\draw[decorate,decoration={brace,mirror,raise=5pt}]
  ({pic cs:start\Value}) -- coordinate (aux-\Value) ({pic cs:end\Value}|-{pic cs:start\Value});
\draw
  ([yshift=-7pt]aux-\Value) -- ++(0pt,-\Length)
  node[below,align=center] {\Text};
}
\end{tikzpicture}

\end{document}

Here are two images from two successive pages:

enter image description here

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127