Schriftart für Tabelleninhalt ändern

Schriftart für Tabelleninhalt ändern

Ich versuche zu folgendieses Beispielum die Schriftart in einer Tabelle zu ändern. Es ist eine Teillösung für den folgenden Code. Ich kann die Werte einfach nicht dazu bringen, auch die Schriftart zu ändern.

\documentclass{article}

\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[format=plain,
  labelformat=simple,
  font={small,sf,bf},
  indention=0cm,
  labelsep=period,
  justification=centering,
  singlelinecheck=true,
  tableposition=top,
  figureposition=bottom]{caption}

\makeatletter
\appto\@floatboxreset{%
  \ifx\@captype\andy@table
    \ttfamily
  \fi
}
\def\andy@table{table}
\makeatother

\begin{document}

Blah blah. Should be a serif font.


\begin{table}
\caption{My title}
\begin{center}
\begin{tabular}{l c c c }
\hline
 & treat x time & treat x time x female & treat x time x female \\
\hline
(Intercept)                         & $-0.03$           & $0.01$           & $-0.83^{*}$       \\
                                    & $[-0.16;\ 0.10]$  & $[-0.13;\ 0.15]$ & $[-0.93;\ -0.73]$ \\
v1                            & $-0.06$           & $-0.06$          & $-0.07$           \\
                                    & $[-0.23;\ 0.11]$  & $[-0.23;\ 0.11]$ & $[-0.18;\ 0.05]$  \\
v2                              & $0.05$            & $-0.03$          &                   \\
                                    & $[-0.04;\ 0.15]$  & $[-0.16;\ 0.11]$ &                   \\
\hline
\multicolumn{4}{l}{\scriptsize{$^*$ 0 outside the confidence interval. Fixed effect of time treated as factor.}}
\end{tabular}
\label{m123}
\end{center}
\end{table}

Blah blah. Should be a serif font.

\end{document}

Bildbeschreibung hier eingeben

Antwort1

Entfernen Sie es einfach $, wo es nicht benötigt wird (also fast überall).

\documentclass{article}

\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[format=plain,
  labelformat=simple,
  font={small,sf,bf},
  indention=0cm,
  labelsep=period,
  justification=centering,
  singlelinecheck=true,
  tableposition=top,
  figureposition=bottom,
]{caption}

\makeatletter
\appto\@floatboxreset{%
  \ifx\@captype\andy@table
    \ttfamily
  \fi
}
\def\andy@table{table}
\makeatother

\begin{document}

Blah blah. Should be a serif font.

\begin{table}
\centering

\caption{My title}\label{m123}

% fix the overfull
\small\addtolength{\tabcolsep}{-2pt}

\begin{tabular}{ l c c c }
\hline
 & treat x time & treat x time x female & treat x time x female \\
\hline
(Intercept) & -0.03         & 0.01          & -0.83$^{*}$    \\
            & [-0.16; 0.10] & [-0.13; 0.15] & [-0.93; -0.73] \\
v1          & -0.06         & -0.06         & -0.07          \\
            & [-0.23; 0.11] & [-0.23; 0.11] & [-0.18; 0.05]  \\
v2          & 0.05          & -0.03         &                \\
            & [-0.04; 0.15] & [-0.16; 0.11] &                \\
\hline
\multicolumn{4}{l}{%
  \scriptsize $^*$ 0 outside the confidence interval. Fixed effect of time treated as factor.%
}
\end{tabular}

\end{table}

Blah blah. Should be a serif font.

\end{document}

Bildbeschreibung hier eingeben

Einige weitere Anmerkungen.

  1. Platzieren Sie das \labelneben dem Objekt, auf das es sich bezieht, in diesem Fall das\caption

  2. \scriptsizenimmt kein Argument an.

  3. Nicht centerin einer tableUmgebung verwenden, aber \centering.


Wenn Sie die vom externen Programm generierte Tabelle nicht berühren möchten, ist es etwas schwieriger.

\documentclass{article}

\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[format=plain,
  labelformat=simple,
  font={small,sf,bf},
  indention=0cm,
  labelsep=period,
  justification=centering,
  singlelinecheck=true,
  tableposition=top,
  figureposition=bottom]{caption}

\makeatletter
\appto\@floatboxreset{%
  \ifx\@captype\andy@table
    \ttfamily
    \everymath{\fam=\group@mathtt\relax\andy@changemathcodes}%
  \fi
}
\def\andy@table{table}
\let\andy@space\ %
\AtBeginDocument{%
  \check@mathfonts
  \sbox\z@{$\mathtt{\xdef\group@mathtt{\gdef\noexpand\group@mathtt{\the\fam}}\group@mathtt}$}%
  \def\andy@changemathcodes{%
    \count@="2\group@mathtt00 \advance\count@`-\mathcode`-=\count@
    \count@="4\group@mathtt00 \advance\count@`[\mathcode`[=\count@
    \count@="5\group@mathtt00 \advance\count@`]\mathcode`]=\count@
    \count@="0\group@mathtt00 \advance\count@`;\mathcode`;=\count@
    \def\ {\mathopen{\andy@space}}%
  }%
}
\makeatother

\begin{document}


Blah blah. Should be a serif font; here's math: $a+b$

\begin{table}
\centering

\caption{With dollars}

% fix the overfull
\small\addtolength{\tabcolsep}{-2pt}

\begin{tabular}{ l c c c }
\hline
& treat x time & treat x time x female & treat x time x female       \\
\hline
(Intercept) & $-0.03$          & $0.01$           & $-0.83^{*}$       \\
            & $[-0.16;\ 0.10]$ & $[-0.13;\ 0.15]$ & $[-0.93;\ -0.73]$ \\
v1          & $-0.06$          & $-0.06$          & $-0.07$           \\
            & $[-0.23;\ 0.11]$ & $[-0.23;\ 0.11]$ & $[-0.18;\ 0.05]$  \\
v2          & $0.05$           & $-0.03$          &                   \\
            & $[-0.04;\ 0.15]$ & $[-0.16;\ 0.11]$ &                   \\
\hline
\multicolumn{4}{l}{%
  \scriptsize$^*$ 0 outside the confidence interval. Fixed effect of time treated as factor.%
}
\end{tabular}

\end{table}



\begin{table}[htp]
\centering

\caption{My title}\label{m123}

% fix the overfull
\small\addtolength{\tabcolsep}{-2pt}

\begin{tabular}{ l c c c }
\hline
 & treat x time & treat x time x female & treat x time x female \\
\hline
(Intercept) & -0.03         & 0.01          & -0.83$^{*}$    \\
            & [-0.16; 0.10] & [-0.13; 0.15] & [-0.93; -0.73] \\
v1          & -0.06         & -0.06         & -0.07          \\
            & [-0.23; 0.11] & [-0.23; 0.11] & [-0.18; 0.05]  \\
v2          & 0.05          & -0.03         &                \\
            & [-0.04; 0.15] & [-0.16; 0.11] &                \\
\hline
\multicolumn{4}{l}{%
  \scriptsize $^*$ 0 outside the confidence interval. Fixed effect of time treated as factor.%
}
\end{tabular}

\end{table}

Blah blah. Should be a serif font; here's math: $a+b$.

\end{document}

Wie Sie sehen, ist die Ausgabe dieselbe.

Bildbeschreibung hier eingeben

Antwort2

Dies nutztKann ich die gesamte mathematische Ausgabe so ändern, dass sie nichtproportionalen Text verwendet?\everymathum den entsprechenden Befehl zu Ihrem Patch hinzuzufügen \@floatboxreset:

Bildbeschreibung hier eingeben

\documentclass{article}

\usepackage{etoolbox}

\makeatletter
\appto\@floatboxreset{%
  \ifx\@captype\andy@table
    \ttfamily
    % https://tex.stackexchange.com/q/119879/5764
    \everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}% 
  \fi
}
\def\andy@table{table}
\makeatother

\begin{document}

\begin{table}
  \begin{tabular}{ l *{3}{c} }
    \hline
     & treat x time & treat x time x female & treat x time x female       \\
    \hline
    (Intercept) & $-0.03$          & $0.01$           & $-0.83^{*}$       \\
                & $[-0.16;\ 0.10]$ & $[-0.13;\ 0.15]$ & $[-0.93;\ -0.73]$ \\
    v1          & $-0.06$          & $-0.06$          & $-0.07$           \\
                & $[-0.23;\ 0.11]$ & $[-0.23;\ 0.11]$ & $[-0.18;\ 0.05]$  \\
    v2          & $0.05$           & $-0.03$          &                   \\
                & $[-0.04;\ 0.15]$ & $[-0.16;\ 0.11]$ &                   \\
    \hline
    \multicolumn{4}{l}{\scriptsize{$^*$ 0 outside the confidence interval. Fixed effect of time treated as factor.}}
  \end{tabular}
\end{table}

\end{document}

Leider ist der Abstand um ein unäres Minus nicht einheitlich. Siehe beispielsweise $a - b$ $-b$ $[-b]$ ${-}b$:

Bildbeschreibung hier eingeben

Möglicherweise müssen Sie verwenden, {-}um bei Bedarf ein unäres Minus zu erzwingen.

verwandte Informationen