\VerbatimInput :調整 .dat 檔案的長行

\VerbatimInput :調整 .dat 檔案的長行

在本文檔中,\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文本嗎?

這些是.textest_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}

在此輸入影像描述

在此輸入影像描述

在此輸入影像描述

相關內容