向节点添加“align=left”时出错

向节点添加“align=left”时出错

我正在尝试在我的图上添加注释,并尝试将其设置为双行。我尝试遵循#123671,使用答案的第二个选项,即向align=left最后一个节点添加一个属性,但会导致一堆错误。

\documentclass[tikz, border = 5pt]{standalone}
\usepackage{siunitx}

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}
    \begin{axis}[
    title={Resposta em frequência},
    width=4.396in,
    height=3.357in,
    at={(0.883in,0.481in)},
    scale only axis,
    separate axis lines,
    every outer x axis line/.append style={white!40!black},
    every x tick label/.append style={font=\color{white!40!black}},
    every x tick/.append style={white!40!black},
    xmode=log,
    xmin=1000,
    xmax=10000000,
    xminorticks=true,
    grid=both,
    xlabel={Frequência (rad/s)},
    every outer y axis line/.append style={white!40!black},
    every y tick label/.append style={font=\color{white!40!black}},
    every y tick/.append style={white!40!black},
    ymin=-70,
    ymax=0,
    ylabel={Magnitude (dB)},
    axis background/.style={fill=white},
    legend style={legend cell align=left, align=left, draw=white!15!black}
    ]
    \addplot [color=mycolor1, forget plot]
    table[row sep=crcr]{
        1e-20   1.54292394648526e-14\\
        6.66666666666759e-13    1.54292394648526e-14\\
        6.66666666666759e-08    1.54292394648526e-14\\
        0.000666666666666758    1.3500584531746e-14\\
        0.666666666666759   -8.26708293805402e-11\\
        66.6666666666759    -8.26870011337924e-07\\
        666.666666666759    -8.26864051082017e-05\\
        778.890771786889    -0.000112867420555789\\
        910.006251562037    -0.000154064535941829\\
        1063.19320741493    -0.000210298517218128\\
        1242.16706682281    -0.000287057571002689\\
        1451.26869804862    -0.000391832834011076\\
        1695.56969443962    -0.000534849219037435\\
        1980.99538188053    -0.000730062865054596\\
        2314.46853284847    -0.000996522438065902\\
        2704.07727273984    -0.00136022707769961\\
        3159.27125090315    -0.00185666252023427\\
        3691.09083434961    -0.0025342640882715\\
        4312.43488305253    -0.00345914868513465\\
        5038.37360151153    -0.00472159019481194\\
        5886.51405454719    -0.00644490524305459\\
        6877.42721261999    -0.00879770872706377\\
        8035.14688431749    -0.0120109680452925\\
        9387.75263721931    -0.0164020856230169\\
        10968.0508454207    -0.022409674821438\\
        12814.3703819796    -0.0306453313338698\\
        14971.4922551726    -0.0419734862598124\\
        17491.7357361468    -0.0576386196036108\\
        20436.2273211267    -0.0794715716557583\\
        23876.3833058438    -0.110221676794693\\
        27895.6419308485    -0.154070365696059\\
        32591.4871095095    -0.217364278615351\\
        38077.8128226072    -0.309529309282892\\
        44487.6855260296    -0.44396210134712\\
        51976.5715715652    -0.63845860167214\\
        60726.1079193109    -0.9145567271784\\
        70948.5075973192    -1.29530106922591\\
        82891.7067593944    -1.80160791283656\\
        96845.3781788223    -2.44842038436318\\
        113147.957030528    -3.24240025243998\\
        132194.849366409    -4.18227950222334\\
        154448.022373859    -5.26153293861644\\
        180447.209021576    -6.47193453834754\\
        210822.998852379    -7.80653534878038\\
        213109.73159745 -7.9035610664232\\
        246312.1324298  -9.26128327747976\\
        287775.370393042    -10.835190417512\\
        336218.370519995    -12.5293360931429\\
        392816.079154819    -14.3451584983039\\
        458941.228594731    -16.2825747032065\\
        536197.631617386    -18.3384872354153\\
        626459.080681065    -20.5061069739647\\
        731914.795266769    -22.775227454851\\
        855122.519651245    -25.1332442683552\\
        999070.558955123    -27.5665022462189\\
        1167250.25810101    -30.0615568686588\\
        1363740.68160092    -32.6060943686751\\
        1593307.54801376    -35.1894426645877\\
        1861518.81864921    -37.802734279119\\
        2174879.74402996    -40.4388332727386\\
        2540990.6435564 -43.092134131087\\
        2968731.24519395    -45.7583125526517\\
        3468476.05619497    -48.4340773664478\\
        4052345.9885005 -51.1169487082971\\
        4734502.34179533    -53.8050718508377\\
        5531490.27454094    -56.4970672009555\\
        6462640.0936024 -59.1919127199115\\
        7550536.09542924    -61.8888535018907\\
        8821564.33015925    -64.5873331695161\\
        10306552.5742267    -67.2869423212165\\
        12041518.0335007    -69.9873800596794\\
        14068540.9118968    -72.6884254256942\\
        16436785.0331718    -75.3899162640424\\
        19203690.2702709    -78.091733629183\\
        22436365.7036484    -80.7937903008019\\
        224363657.036484    -120.792010521114\\
        22436365703.6484    -200.791992541865\\
        22436365703648.4    -320.791992540067\\
        2.24363657036484e+17    -480.791992540067\\
        1e+20   -586.753892131313\\
    };

    \addplot [black, mark=*, mark options={draw=black}, only marks]
    coordinates {
        (1.08e5,-3.01) 
    };
 % This last node causes the error when the align=left is present, and without this property, it works fine, but the annotation keeps one-lined

    \node at (axis cs:1.08e5,-3.01) [draw,align=left,anchor=north east,fill=white] {$\omega_{CROSS} = \\ 1.08\cdot10^5\SI[per-mode=symbol]{}{\radian\per\second}$};
    \end{axis}
\end{tikzpicture}

\end{document}

答案1

为节点定义对齐允许您在其中换行。但在数学模式下您不能换行(via \\)。因此,您必须在节点的每一行上打开/关闭数学模式。

下面我使用了align=center(而不是left代码中的 as)。此外,我更喜欢 在科学计数法中使用\times而不是\cdot进行乘法。

\node at (axis cs:1.08e5,-3.01) 
  [draw, align=center, anchor=north east, fill=white] {
  $\omega_{\mathrm{CROSS}} = $ \\       % <--- close math here
  $1.08 \times 10^5\SI[per-mode=symbol]{}{\radian\per\second}$
  }; 

在此处输入图片描述

平均能量损失

\documentclass[tikz, border = 5pt]{standalone}
\usepackage{siunitx}

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}
    \begin{axis}[
    title={Resposta em frequência},
    width=4.396in,
    height=3.357in,
    at={(0.883in,0.481in)},
    scale only axis,
    separate axis lines,
    every outer x axis line/.append style={white!40!black},
    every x tick label/.append style={font=\color{white!40!black}},
    every x tick/.append style={white!40!black},
    xmode=log,
    xmin=1000,
    xmax=10000000,
    xminorticks=true,
    grid=both,
    xlabel={Frequência (rad/s)},
    every outer y axis line/.append style={white!40!black},
    every y tick label/.append style={font=\color{white!40!black}},
    every y tick/.append style={white!40!black},
    ymin=-70,
    ymax=0,
    ylabel={Magnitude (dB)},
    axis background/.style={fill=white},
    legend style={legend cell align=left, align=left, draw=white!15!black}
    ]
    \addplot [color=mycolor1, forget plot]
    table[row sep=crcr]{
        1e-20   1.54292394648526e-14\\
        6.66666666666759e-13    1.54292394648526e-14\\
        6.66666666666759e-08    1.54292394648526e-14\\
        0.000666666666666758    1.3500584531746e-14\\
        0.666666666666759   -8.26708293805402e-11\\
        66.6666666666759    -8.26870011337924e-07\\
        666.666666666759    -8.26864051082017e-05\\
        778.890771786889    -0.000112867420555789\\
        910.006251562037    -0.000154064535941829\\
        1063.19320741493    -0.000210298517218128\\
        1242.16706682281    -0.000287057571002689\\
        1451.26869804862    -0.000391832834011076\\
        1695.56969443962    -0.000534849219037435\\
        1980.99538188053    -0.000730062865054596\\
        2314.46853284847    -0.000996522438065902\\
        2704.07727273984    -0.00136022707769961\\
        3159.27125090315    -0.00185666252023427\\
        3691.09083434961    -0.0025342640882715\\
        4312.43488305253    -0.00345914868513465\\
        5038.37360151153    -0.00472159019481194\\
        5886.51405454719    -0.00644490524305459\\
        6877.42721261999    -0.00879770872706377\\
        8035.14688431749    -0.0120109680452925\\
        9387.75263721931    -0.0164020856230169\\
        10968.0508454207    -0.022409674821438\\
        12814.3703819796    -0.0306453313338698\\
        14971.4922551726    -0.0419734862598124\\
        17491.7357361468    -0.0576386196036108\\
        20436.2273211267    -0.0794715716557583\\
        23876.3833058438    -0.110221676794693\\
        27895.6419308485    -0.154070365696059\\
        32591.4871095095    -0.217364278615351\\
        38077.8128226072    -0.309529309282892\\
        44487.6855260296    -0.44396210134712\\
        51976.5715715652    -0.63845860167214\\
        60726.1079193109    -0.9145567271784\\
        70948.5075973192    -1.29530106922591\\
        82891.7067593944    -1.80160791283656\\
        96845.3781788223    -2.44842038436318\\
        113147.957030528    -3.24240025243998\\
        132194.849366409    -4.18227950222334\\
        154448.022373859    -5.26153293861644\\
        180447.209021576    -6.47193453834754\\
        210822.998852379    -7.80653534878038\\
        213109.73159745 -7.9035610664232\\
        246312.1324298  -9.26128327747976\\
        287775.370393042    -10.835190417512\\
        336218.370519995    -12.5293360931429\\
        392816.079154819    -14.3451584983039\\
        458941.228594731    -16.2825747032065\\
        536197.631617386    -18.3384872354153\\
        626459.080681065    -20.5061069739647\\
        731914.795266769    -22.775227454851\\
        855122.519651245    -25.1332442683552\\
        999070.558955123    -27.5665022462189\\
        1167250.25810101    -30.0615568686588\\
        1363740.68160092    -32.6060943686751\\
        1593307.54801376    -35.1894426645877\\
        1861518.81864921    -37.802734279119\\
        2174879.74402996    -40.4388332727386\\
        2540990.6435564 -43.092134131087\\
        2968731.24519395    -45.7583125526517\\
        3468476.05619497    -48.4340773664478\\
        4052345.9885005 -51.1169487082971\\
        4734502.34179533    -53.8050718508377\\
        5531490.27454094    -56.4970672009555\\
        6462640.0936024 -59.1919127199115\\
        7550536.09542924    -61.8888535018907\\
        8821564.33015925    -64.5873331695161\\
        10306552.5742267    -67.2869423212165\\
        12041518.0335007    -69.9873800596794\\
        14068540.9118968    -72.6884254256942\\
        16436785.0331718    -75.3899162640424\\
        19203690.2702709    -78.091733629183\\
        22436365.7036484    -80.7937903008019\\
        224363657.036484    -120.792010521114\\
        22436365703.6484    -200.791992541865\\
        22436365703648.4    -320.791992540067\\
        2.24363657036484e+17    -480.791992540067\\
        1e+20   -586.753892131313\\
    };

    \addplot [black, mark=*, mark options={draw=black}, only marks]
    coordinates {
        (1.08e5,-3.01) 
    };

    \node at (axis cs:1.08e5,-3.01) [draw,align=center,anchor=north east,fill=white] {$\omega_{\mathrm{CROSS}} = $ \\ $1.08\times 10^5\SI[per-mode=symbol]{}{\radian\per\second}$};
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容