dirtree是一個比較簡單的宏包,用於繪製目錄樹。在LaTeX文檔中繪製目錄樹時,如果要求不高的話,可以直接從終端窗口複製tree命令的顯示結果,粘貼到文檔中。如果想好看一點,就用這個宏包吧。要求更高的話可以使用tikz繪圖宏包來繪製。
dirtree宏包的幫助文檔已經放在百度網盤上免費供大家參閱,請看我的另一篇日誌“LaTeX——部分宏包幫助文檔百度網盤下載”,上面有地址與提取碼。
操作系統:Ubuntu 18.04 編輯工具:TeXstudio 2.12.6 編譯方式:LuaLaTeX
% 開源中國,陸巍
\documentclass{article}%
%
\usepackage{ctex}% 中文支持
\usepackage{geometry}% 用於頁面設置
\usepackage[english]{babel}% 載入美式英語斷字模板
\usepackage[dvipsnames, svgnames, x11names]{xcolor}% 顏色支持
\usepackage{colortbl}% 表格顏色支持
\usepackage{dirtree} % 繪製目錄樹
% 設置爲A4紙,並設置邊距
\geometry
{
a4paper,%
left = 3.17cm,%
right = 3.17cm,%
top = 2.54cm,%
bottom = 2.54cm%
}%
\setlength{\parindent}{0em}% 縮進爲0
% ------------------ 開始 -------------------
%
\begin{document}
\section{示例一}
% 注意\dirtree{後面的%符號一定要添加,否則出錯。
% 每一行語句後面要有字符.
\dirtree{%
.1 ..
.2 build.
.2 camke.
.2 include.
.2 src.
.2 \textcolor{teal}{CMakelists.txt}.
}
\section{示例二}
\fcolorbox{black}{black}{
\color{white}
\begin{minipage}{\linewidth}
% 注意\dirtree{後面的%符號一定要添加,否則出錯。
% 每一行語句後面要有字符.
\dirtree{%
.1 ..
.2 \textcolor{cyan}{bin}.
.3 \textcolor{green}{cmake-annotate}.
.3 \textcolor{green}{cmake-format}.
.3 \textcolor{green}{cmake-genparsers}.
.3 \textcolor{green}{cmake-lint}.
.3 \textcolor{green}{ctest-to}.
.2 \textcolor{cyan}{etc}.
.2 \textcolor{cyan}{games}.
.2 \textcolor{cyan}{include}.
.3 \textcolor{cyan}{gmock}.
.3 \textcolor{cyan}{gtest}.
.2 \textcolor{cyan}{lib}.
.3 libgmock.a.
.3 libgmock\_main.a.
.3 libgtest.a.
.3 libgtest\_main.a.
.3 \textcolor{cyan}{python2.7}.
.3 \textcolor{cyan}{python3.6}.
.2 \textcolor{Aqua}{man} -> \textcolor{cyan}{share/man}.
.2 \textcolor{cyan}{sbin}.
.2 \textcolor{cyan}{share}.
.3 \textcolor{cyan}{ca-certificates}.
.3 \textcolor{cyan}{emacs}.
.3 \textcolor{cyan}{fonts}.
.3 \textcolor{cyan}{man}.
.3 \textcolor{cyan}{sgml}.
.3 \textcolor{cyan}{texmf}.
.2 \textcolor{cyan}{src}.
}
\end{minipage}
}
\end{document}
效果如下:
注意事項:
1、第一行語句“\dirtree{”後面要添加%符號;
2、\dirtree{}命令內的每一行後面要有小數點。