Why do some negative numbers produce weird characters with fontenc package?
The characters −
in the last two rows are U+2212, which in UTF-8 is input as <E2><88><92>
and T1 encoded fonts happen to have â
, Ĺ
and Š
at those locations. Without fontenc
you get no output, but warnings about missing characters.
Use also inputenc
:
\documentclass[a4paper,10pt,openany]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\DeclareUnicodeCharacter{2212}{-} % if U+2212 slips in
\newcommand{\ctype}[1]{\texttt{#1}}
\sisetup{group-separator={,}}
\begin{document}
\begin{tabular}{
|l|
S[table-format=2.0]|
S[table-format=1.0]|
S[table-format=-19.0]|
S[table-format=19.0]|
}
\hline
Type & {Bits} & {Bytes} & {Minimum} & {Maximum} \\ \hline
\ctype{int8\_t} & 8 & 1 & -128 & 127 \\ \hline
\ctype{int16\_t} & 16 & 2 & -32768 & 32767 \\ \hline
\ctype{int32\_t} & 32 & 4 & −2147483648 & 2147483647 \\ \hline
\ctype{int64\_t} & 64 & 8 & −9223372036854775808 & 9223372036854775807 \\ \hline
\end{tabular}
\end{document}
(I removed minted
because the definition of \ctype
gave errors.)
Just for improvement, loading booktabs
and changing the table into
\begin{tabular}{
@{}
l
S[table-format=2.0]
S[table-format=1.0]
S[table-format=-19.0]
S[table-format=19.0]
@{}
}
\toprule
Type & {Bits} & {Bytes} & {Minimum} & {Maximum} \\
\midrule
\ctype{int8\_t} & 8 & 1 & -128 & 127 \\
\ctype{int16\_t} & 16 & 2 & -32768 & 32767 \\
\ctype{int32\_t} & 32 & 4 & −2147483648 & 2147483647 \\
\ctype{int64\_t} & 64 & 8 & −9223372036854775808 & 9223372036854775807 \\
\bottomrule
\end{tabular}
I also removed the setting for group-separator
, which leaves the default thin space:
This is extended comment:
I wonder how is possible that -
sign has different characters in the first two rows and last two rows in the OP MWE. In the following MWE I only retype -
characters (and also consider table formatting of egreg second example) and it works without \DeclareUnicodeCharacter{2212}{-}
and with and without \usepackage[T1]{fontenc}
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{array,booktabs}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{
>{\color{purple}}r
S[table-format=2.0]
S[table-format=1.0]
S[table-format=-19.0]
S[table-format= 19.0]
}
\toprule
\verb+int8_t+ & 8 & 1 & -128 & 127 \\
\midrule
\verb+int16_t+ & 16 & 2 & -32768 & 32767 \\
\verb+int32_t+ & 32 & 4 & -2147483648 & 2147483647 \\
\verb+int64_t+ & 64 & 8 & -9223372036854775808 & 9223372036854775807 \\
\bottomrule
\end{tabular}
\end{document}
I use WinEdt for editor preset to utf8
encodiding, if this matter.