![在列表中添加 linux tree 命令输出](https://linux22.com/image/471114/%E5%9C%A8%E5%88%97%E8%A1%A8%E4%B8%AD%E6%B7%BB%E5%8A%A0%20linux%20tree%20%E5%91%BD%E4%BB%A4%E8%BE%93%E5%87%BA.png)
我将树命令输出复制到列表中但编译失败。
\documentclass[12pt,a4paper]{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
.
├── ./a.tex
├── ./b.aux
├── ./b.log
├── ./b.pdf
├── ./#b.tex#
├── ./b.tex
└── ./out.tar.gz
\end{lstlisting}
\end{document}
失败消息:
! LaTeX Error: Invalid UTF-8 byte sequence (�\lst@FillFixed@\lst@EC�).
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.6 ├──
./a.tex
答案1
您可以通过在选项中指定这些字符来替换它们literate
。(给出的是我自己的代码的副本,可能包含一些您不需要的替换。)
\documentclass[12pt,a4paper]{article}
\usepackage{listings}
% ~~~ listings ~~~~~~~~~
\lstset{breaklines=true,%
basicstyle=\footnotesize,%
literate={│}{|}1 {│ }{x}1 {└─}{y}1 {─}{-}1 {├}{+}1,
frame={top|bottom},
}
\begin{document}
\begin{lstlisting}
.
├── ./a.tex
├── ./b.aux
├── ./b.log
├── ./b.pdf
├── ./#b.tex#
├── ./b.tex
└── ./out.tar.gz
\end{lstlisting}
\end{document}