
在本文檔中,\VerbatimInput
正在呼叫test_2.dat
.
test_2.dat
包含的行太長,因此編譯產生的 pdf 中該行沒有完全可見:
透過使用adjustbox
,可以調整逐字文字:
\begin{adjustbox}{max width=\linewidth}
\begin{BVerbatim}
text
\end{BVerbatim}
\end{adjustbox}
然而,該解決方案僅在直接逐字引入文本時才有效。
我必須使用,\VerbatimInput
因為我需要呼叫這個tesst_2.dat
檔案。
有沒有辦法包含adjustbox
在裡面\VerbatimInput
?
或者有什麼解決方案可以縮小這個\VerbatimInput
文本嗎?
這些是.tex
和test_2.dat
文件:
\documentclass[12pt]{article}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{fancyvrb}
\usepackage{color,soul}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}%
{fontsize=\footnotesize,
%
frame=lines, % top and bottom rule only
framesep=2em, % separation between frame and text
rulecolor=\color{Gray},
%
label=\fbox{\color{Black}test.dat},
labelposition=topline,
%
%commandchars=\|\(\), % escape character and argument delimiters for
% commands within the verbatim
%commentchar=* % comment character
}
\VerbatimInput{./test_2.dat}
\end{document}
文件test_2.dat
:
#####l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220
14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220
14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220
14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220
14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220
14.756876 # -> reorientation volumregfddfg
#l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
#l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
####l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
#l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
#l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
#####l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
####l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
####l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
#l.253:
AL BL LC AA BB CC E
2.75319 2.75319 2.75319 60.67009 65.70804 68.04220 14.756876 # -> reorientation volumregfddfg
新編輯:根據@egreg的評論:
我正在使用\BVerbatimInput
, ,\begin{adjustbox}
如下所示,但這會產生一個沒有分頁符號的 pdf,並且文件的其餘內容test_2.dat
不會出現:
有沒有辦法讓test_2.dat
文件正常顯示: - 讓test_2.dat
文件佔據所需的 pdf 頁數 - ?
\documentclass[12pt]{article}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{adjustbox}
\usepackage{fancyvrb}
\usepackage{color,soul}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\begin{adjustbox}{max width=\linewidth}
\RecustomVerbatimCommand{\BVerbatimInput}{BVerbatimInput}%
{fontsize=\footnotesize,
%
frame=lines, % top and bottom rule only
framesep=2em, % separation between frame and text
rulecolor=\color{Gray},
%
label=\fbox{\color{Black}test.dat},
labelposition=topline,
%
%commandchars=\|\(\), % escape character and argument delimiters for
% commands within the verbatim
%commentchar=* % comment character
}
\BVerbatimInput{./test_2.dat}
\end{adjustbox}
\end{document}
答案1
我看不到“自動”的方法來做到這一點,但你可以輕鬆地調整字體大小:在你的設定中,
\fontsize{7}{9}\selectfont
很好。
\documentclass[12pt]{article}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{fancyvrb}
\usepackage{color,soul}
\usepackage[dvipsnames]{xcolor}
\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}{
fontsize=\footnotesize % default
%
frame=lines, % top and bottom rule only
framesep=2em, % separation between frame and text
rulecolor=\color{Gray},
%
label=\fbox{\color{Black}test.dat},
labelposition=topline,
%
%commandchars=\|\(\), % escape character and argument delimiters for
% commands within the verbatim
%commentchar=* % comment character
}
\begin{document}
\VerbatimInput[fontsize=\fontsize{7}{9}\selectfont]{\jobname.dat}
\end{document}
您可能需要添加
\RequirePackage{fix-cm}
\documentclass
如果您想對字體大小進行更精細的控制,請在文件最頂部的 之前。
答案2
這裡有一些可能性,使用verbatimbox
.
\documentclass[12pt]{article}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{fancyvrb}
\usepackage{color,soul}
\usepackage[dvipsnames]{xcolor}
\usepackage{verbatimbox}
\begin{document}
\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}%
{fontsize=\footnotesize,
%
frame=lines, % top and bottom rule only
framesep=2em, % separation between frame and text
rulecolor=\color{Gray},
%
label=\fbox{\color{Black}test.dat},
labelposition=topline,
%
%commandchars=\|\(\), % escape character and argument delimiters for
% commands within the verbatim
%commentchar=* % comment character
}
% \VerbatimInput{./test_2.dat}
%\clearpage
\noindent\hrulefill\raisebox{-2pt}{\fbox{\color{Black}shifted test.dat}}\hrulefill
\verbfilenobox[\leavevmode\kern-35pt\scriptsize]{./test_2.dat}
\clearpage
\noindent\hrulefill\raisebox{-2pt}{\fbox{\color{Black}blank lines retained tiny test.dat}}\hrulefill
\verbfilenobox[\leavevmode\tiny]{./test_2.dat}
\clearpage
\noindent\hrulefill\raisebox{-2pt}{\fbox{\color{Black}tiny test.dat}}\hrulefill
\verbfilenobox[\tiny]{./test_2.dat}
\clearpage
\noindent\hrulefill\raisebox{-2pt}{\fbox{\color{Black}too wide test.dat}}\hrulefill
\verbfilenobox{./test_2.dat}
\end{document}