我有一系列用 Excel 创建的“图表”(在发现之前LaTeX
)来显示旧计算机的 ROM 字符模式,以便纳入有关复古计算的书籍中。
我的难题是如何将它们插入书中。我假设每个都应该是一张单独的图像,这样我就可以将LaTeX
它们正确地格式化为网格模式,但我也想知道TikZ
Inkscape 是否是更好的方法。
我总共需要 128 个字符。左下角的字符来自 TTF 字体。我正在使用,XeTeX
所以包含该字体没有问题。
从学习曲线、便利性和最终文档的外观来看,“最佳”方法是什么?
答案1
请注意,symbol node
样式应该具有适合特殊字体的正确字体设置。我的positioning-plus
已用于west below
可替换为原始密钥positioning
和 TikZ 密钥的密钥:west below=<distance> of node
与 相同below=<distance> of node.south west, anchor=north west
。
代码
\documentclass[tikz,convert=false]{standalone}%
\usetikzlibrary{chains,positioning-plus}
\pgfkeys{%
/handlers/.tikz/.code=\pgfkeys{\pgfkeyscurrentpath/.code=\tikzset{#1}},%
/handlers/.append tikz/.code=\pgfkeys{\pgfkeyscurrentpath/.append code=\tikzset{#1}},%
/handlers/.prefix tikz/.code=\pgfkeys{\pgfkeyscurrentpath/.prefix code=\tikzset{#1}}}
\newcommand*{\letterset}{\pgfqkeys{/letter}}
\letterset{
@int/start chain/.style={start chain=ch#1 going right},
columns/.initial=8,
rows/.initial={0,0,0,0,0,0,0},
column width/.initial=+.5cm,
row height/.initial=+.6cm,
%
every letter picture/.tikz={
node distance=+0pt,
every node/.append style={
minimum width=\pgfkeysvalueof{/letter/column width},
minimum height=\pgfkeysvalueof{/letter/row height},
text depth=+0pt,
outer sep=+0pt,
}},
every header label/.tikz={font=\tiny,rotate=90,inner sep=+0pt,outer sep=+0pt},
every cell node/.tikz={draw=gray, ultra thin},
every 1 node/.tikz={fill=black},
every 0 node/.tikz={},
data column node/.tikz={
align=right,
text width=\widthof{000}
},
symbol node/.tikz={
font=\ttfamily}% Here should stand the command for the XeTeX font
}
\makeatletter
\newcommand{\letterChart}[4][]{%
\begingroup
\pgfqkeys{/letter}{#1}%
\pgfkeysgetvalue{/letter/columns}\letter@Columns
\pgfmathsetbasenumberlength{\letter@Columns}%
\pgfkeysgetvalue{/letter/rows}\letter@Rows
\tikzpicture[/letter/every letter picture/.try, /letter/@int/start chain/.list/.expanded={0,1,...,\letter@Columns}]
\node[anchor=west,/letter/head node/.try] (letter@head) {Bit Values of Pixels};
\foreach \letter@Power in {1,...,\letter@Columns} {
\ifnum\letter@Power=1\tikzset{/letter/@int/first node/.tikz={west below=of letter@head}}\fi
\node[on chain=ch0,/letter/@int/first node/.try,/letter/header node/.try,label={[/letter/every header label/.try]center:\pgfmathprint{int(2^(\letter@Columns-\letter@Power))}}] {};
}
\foreach \letter@Row[count=\c@prevRow from 0, count=\c@Row] in \letter@Rows {%
\pgfmathbin{\letter@Row}
\edef\letter@Digits{\expandafter\letter@IncludeComma\pgfmathresult\stop@Letter}
\foreach \letter@Digit[count=\c@Col] in \letter@Digits{
\ifnum\c@Col=1\tikzset{/letter/@int/first node/.tikz={below=of ch\c@prevRow-begin}}\fi
\node[on chain=ch\c@Row,/letter/@int/first node/.try,/letter/every cell node/.try, /letter/every \letter@Digit\space node/.try] {};
}
\node[/letter/data column node/.try, right=\pgfkeysvalueof{/letter/column width} of ch\c@Row-end] (letter@datacolumn) {\letter@Row};
}
\node[anchor=base east, /letter/head node/.try] at ([email protected]|[email protected]) {Data};
\node[below=\pgfkeysvalueof{/letter/row height} of letter@datacolumn, /letter/data column node/.try] (letter@ascii) {#3};
\node[mid left=of letter@ascii] {ASCII Code:};
\node[below=of letter@ascii, /letter/data column node/.try] (letter@screen) {#4};
\node[mid left=of letter@screen] {Screen Code:};
\node[anchor=base west, /letter/symbol node/.try] at ([email protected]|[email protected] west) {#2};
\endtikzpicture
\endgroup
}
\def\letter@IncludeComma#1#2{%
#1%
\ifx\stop@Letter#2
\expandafter\pgfutil@gobble
\else
\expandafter\pgfutil@firstofone
\fi
{,\letter@IncludeComma#2}}
\makeatother
\begin{document}
\letterChart[rows={60,102,110,110,96,98,60,0}]{@}{64}{0}
\letterChart[rows={24,60,102,102,126,102,102,0}]{A}{65}{1}
\letterChart[rows={124,102,102,124,102,102,124,0}]{B}{66}{2}
\letterset{
every letter picture/.append tikz={node distance=+3pt},
/tikz/nodes={minimum width=\pgfkeysvalueof{/letter/column width}-3pt,
minimum height=\pgfkeysvalueof{/letter/row height}-3pt},
every cell node/.append tikz={shape=circle,draw=none},
column width/.initial=+.5cm,
row height/.initial=+.5cm}
\letterChart[rows={60,102,110,110,96,98,60,0}]{@}{64}{0}
\letterChart[rows={24,60,102,102,126,102,102,0}]{A}{65}{1}
\letterChart[rows={124,102,102,124,102,102,124,0}]{B}{66}{2}
\end{document}
输出
答案2
根据 Ethan Bolker 的建议,我会将它们直接从 Excel 导出为pdf
。将所有pdf
文件放在一个文件夹中。然后,您可以使用以下循环裁剪所有pdfs
:
for img in *.pdf
do
convert -quality 100 -crop 300x100+20+50 "$img" "new_$img"
echo $img
done
其中:300
是宽度,100
是高度,20
是 x 轴上裁剪的部分,50
是 y 轴上裁剪的部分。
--> (20,50)
是图像的左上角。
如果您对该比例有问题,您可以添加-scale 100%
到命令中。
笔记:为了使此循环有用,您要导出的所有字符必须具有相同的大小。
答案3
从头开始尝试使用 LaTeX:
\documentclass{article}
\usepackage{colortbl,xcolor}
\usepackage{booktabs}
\usepackage{array}
\usepackage{rotating,hhline}
\providecommand{\X}{\cellcolor{red!50}}
\providecommand{\CR}{\hhline{--------~-}}
%\renewcommand\arraystretch{1}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{9}{l}{Bit values of Pixels} &
\multicolumn{1}{c}{Data}\\
\multicolumn{1}{c}{}\\
\multicolumn{1}{c}{\begin{sideways}\small 128\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 64\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 32\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 16\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 8\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 4\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 2\end{sideways}} &
\multicolumn{1}{c}{\begin{sideways}\small 1\end{sideways}} &
\multicolumn{1}{c}{}\\
\CR & & & \X & \X & & & & & 24\\
\CR & & \X & \X & \X & \X & & & & 60\\
\CR & \X & \X & & & \X & \X & & & 102\\
\CR & \X & \X & & & \X & \X & & & 102\\
\CR & \X & \X & \X & \X & \X & \X & & & 126\\
\CR & \X & \X & & & \X & \X & & & 102\\
\CR & \X & \X & & & \X & \X & & & 102\\
\CR & & & & & & & & & 0\\
\CR
\end{tabular}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{>{\centering}p{1cm}}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{}\\
\cline{1-1} \cline{10-10}
A & \multicolumn{8}{r|}{ASCII Code:} & 64\\
\cline{1-1} \cline{10-10}
\multicolumn{1}{c}{} & \multicolumn{8}{r|}{Screen Code:} & \\
\cline{10-10}
\end{tabular}
\end{document}