数学模式和非数学模式下的文本格式

数学模式和非数学模式下的文本格式

当我想在数学模式中对齐文本字体时遇到一个问题,代码如下:

\documentclass[xcolor=x11names,compress]{beamer}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{amsmath,amssymb}

\definecolor{Gray}{gray}{0.85}

\begin{document} 

\begin{frame}{I$^{2}$C contd}
Follow figure shows a master writes data to slave with 7-bits address:
%\vspace{-2.5em}
\begin{figure}
\centering
\hspace*{-1.5em}
\begin{tikzpicture}
%    \draw[gray] (0,0) grid (12,8);
%    \foreach \x in {0,1,...,12}
%           \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
%    \foreach \y in {1,2,...,8}
%       \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};

    %draw data structure
    \draw [fill=Gray] (0,5.5)    rectangle (1,6)    node[pos=.5] {S};
    \draw [fill=Gray] (1,5.5)    rectangle (4.5,6)  node[pos=.5] {SLAVE ADDRESS};
    \draw [fill=Gray] (4.5,5.5)  rectangle (5.5,6)  node[pos=.5] {R/$\overline{W}$};
    \draw             (5.5,5.5)  rectangle (6,6)    node[pos=.5] {A};
    \draw [fill=Gray] (6,5.5)    rectangle (7.5,6)  node[pos=.5] {DATA};
    \draw             (7.5,5.5)  rectangle (8,6)    node[pos=.5] {A};
    \draw [fill=Gray] (8,5.5)    rectangle (9.5,6)  node[pos=.5] {DATA};
    \draw             (9.5,5.5)  rectangle (11,6)   node[pos=.5] {A/$\overline{A}$};
    \draw [fill=Gray] (11,5.5)   rectangle (11.5,6) node[pos=.5] {P};

    %draw example
    \draw [fill=Gray] (0.5,3) rectangle (1,3.5);
    \draw             (0.5,2) rectangle (1,2.5);

    %draw line
    \draw (5,5.3) -- (5,4.5);
    \draw (6,5.3) -- (6,4.5) -- (6.5,4.5);
    \draw (11,5.3) -- (11,4.5) -- (10.5,4.5);

    %add text
    %\coordinate [label={[blue]above:`0'(write)}] (RW) at (5,4);
    %\coordinate [label={[blue]above:`0'(data transferred \\())}] (RW) at (8.5,4);
    \node [blue, align=center, above] at (5,4) {`0'(write)};
    \node [blue, align=center, above] at (8.5,4) {data transferred \\(n bytes + ACK)};
    \node [red, align=left, above] at (2.8,3) {from master to slave};
    \node [red, align=left, above] at (2.8,2) {from slave to master};
    \node [red, align=left, above] at (8, 3) {A$=$ACK (SDA LOW)};
    \node [red, align=left, above] at (8, 2.5) {$\overline{A}=$NAK (SDA HIGH)};
    \node [red, align=left, above] at (7.1, 2) {S=START};
    \node [red, align=left, above] at (7, 1.5) {P=STOP};



\end{tikzpicture}
\end{figure}
\end{frame}

\end{document}

输出为: 在此处输入图片描述 如何将数学模式下的字体更改为我在数学模式之外使用的相同字体?

答案1

如果您想在数学环境中使用非数学符号,可以使用命令\mathrm或。\text

使用哪一个?:对于何时使用 \text 和 \mathrm 有何偏好?

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\node[draw] {$\overline{A}$};
\node[draw] at (1,0) {$\overline{\text{A}}$};
\node[draw] at (2,0) {$\overline{\mathrm{A}}$};

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容