Re: プログラムリスト

名前: 角藤
日時: 2001-10-27 16:21:28
IPアドレス: 203.165.2.*

>>3152 >コンピューター雑誌でよく見掛ける、「下地がグレー、プログラムのコードは白抜き」 >というスタイルを実現したいのですが、なにか良い方法はないでしょうか? >なお、コードの部分は verbatim 環境を使用して表示しています。 >以上よろしくお願いします。 \documentclass[12pt]{jarticle} \usepackage[dvips]{color} \usepackage{asndpage} \definecolor{shadecolor}{gray}{.6} \definecolor{code}{gray}{1} \begin{document} 簡単なCプログラムです: \begin{shaded} {% \color{code} \begin{verbatim} int main(int argc, char *argv[]) { printf("Hello.\n"); return 0; } \end{verbatim} }% \end{shaded} 簡単なCプログラムでした。 \end{document} asndpage.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create framed or shaded regions that can break across pages using % \begin{framed} ... \end{framed} -- ordinary frame box (box at margin) % \begin{shaded} ... \end{shaded} -- shaded background (into margin) % % The "framed" environment puts the text into "\fbox" with the % settings "\fboxrule=\FrameRule" and "\fboxsep=\FrameSep". % You can change these lengths (using "\setlength") and you % can even change the definition of "\FrameCommand" to use % much fancier boxes. % % In fact, the "shaded" environment just redefines "\FrameCommand" % to use "\colorbox{shadecolor}" (and you have to define the % color "shadecolor"). % Donald Arseneau \def\FrameCommand{\fboxrule=\FrameRule \fboxsep=\FrameSep \fbox} \newdimen\FrameRule \FrameRule=0.4pt \newdimen\FrameSep \FrameSep = 2\fboxsep \newenvironment{framed}% using default \FrameCommand {\fram@d {\advance\hsize-\width}}% {\endfram@d} \newenvironment{shaded}{% \def\FrameCommand{\colorbox{shadecolor}}% \fram@d {}}% {\endfram@d} \def\fram@d#1{\par \begingroup \skip@\lastskip \penalty\@M % updates \page parameters \ifdim\pagefilstretch=\z@ \ifdim\pagefillstretch=\z@ \if@nobreak\else \vskip-\skip@ \penalty-30 \vskip\skip@ \fi\fi\fi \addvspace{\topsep}% \endgroup \fb@adjheight \penalty\@M % updates \pagetotal \setbox\@tempboxa\vbox\bgroup % measure added width and height; call result \width and \height \setbox\z@\vbox{\vskip-1in \hbox{\hskip-1in \FrameCommand{\hbox{\vrule \@height 1in \@width 1in}}% }\vskip\z@skip}% \def\width{\wd\z@}\def\height{\height\z@}% #1% Modifications to \hsize (can use \width and \height) \textwidth\hsize \columnwidth\hsize \@parboxrestore } \def\endfram@d{\par \kern\z@ \penalty-100 % put depth into height \egroup \begingroup \put@frame \endgroup } \def\put@frame{% % \message{Entering putframe. }% \dimen@\pagegoal \advance\dimen@-\pagetotal % space left on page \ifdim\dimen@>\baselineskip % there's some room left \advance\dimen@.6\pageshrink % room available for box on page \advance\dimen@-\tw@\fboxrule \advance\dimen@-\tw@\fboxsep % " for text % \ifdim\pagefilstretch>\z@ \dimen@\maxdimen\fi % don't split, even if... % \ifdim\pagefillstretch>\z@ \dimen@\maxdimen\fi% does not fit \ifdim\dimen@>\ht\@tempboxa % whole box does fit % \message{Box of size \the\ht\@tempboxa\space fits in \the\dimen@: % \string\pagetotal=\the\pagetotal, % \string\pagegoal=\the\pagegoal, % \string\pagestretch=\the\pagestretch, % \string\pageshrink=\the\pageshrink. }% \else % box must be split % \message{Box of size \the\ht\@tempboxa\space must be split for \the\dimen@: % \string\pagetotal=\the\pagetotal, % \string\pagegoal=\the\pagegoal, % \string\pagestretch=\the\pagestretch, % \string\pageshrink=\the\pageshrink, % \string\fboxsep=\the\fboxsep, % \string\fboxrule=\the\fboxrule. }% \dimen@\pagegoal \advance\dimen@-\pagetotal % space left on page \setbox\@tempboxa\vbox{\advance\fboxsep\fboxrule \vskip\tw@\fboxsep plus\pagestretch minus.6\pageshrink \kern137sp\kern-137sp\penalty-30 \unvbox\@tempboxa}% \boxmaxdepth\z@ \splittopskip\z@ % \message{Box of size \the\ht\@tempboxa\space is split to \the\dimen@. }% \setbox\tw@\vsplit\@tempboxa to\dimen@ \setbox\tw@\vbox{\unvbox\tw@}% % \message{Natural height of split box is \the\ht\tw@. }% \advance\dimen@.8\pageshrink \ifdim\ht\tw@>\dimen@ \advance\dimen@-\tw@\fboxsep \advance\dimen@-\tw@\fboxrule % \message{Box too tall; rebox it to \the\dimen@. }% \setbox\tw@\vbox to\dimen@ \else \setbox\tw@\vbox \fi \bgroup \advance\fboxsep\fboxrule \vskip-\tw@\fboxsep plus-\pagestretch minus-.6\pageshrink \unvbox\tw@ \ifdim\lastkern=-137sp % whole box went to next page % \message{box split at beginning! }% \egroup \eject % (\vskip for frame size was discarded) \fb@adjheight \else % \egroup \ifvoid\@tempboxa % it all fit after all % \message{box split at end! }% \setbox\@tempboxa\box\tw@ \else % it really did split % \message{box split as expected. Its reboxed height is \the\ht\tw@. }% \centerline{\FrameCommand{\box\tw@}}% \hrule height\z@ \eject \fb@adjheight \put@frame \fi\fi\fi\fi \ifvoid\@tempboxa\else \centerline{\FrameCommand{\box\@tempboxa}}\hrule height\z@ \penalty-30 \vskip\topsep \nobreak \prevdepth\z@ \fi} \def\fb@adjheight{\null % get proper baselineskip from above. \hrule \@height\z@ \@width\z@ \penalty\@M \vskip-1.2ex\relax} % useful for tops of pages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Donald Arseneau


メッセージ(タグは <a href="...">...</a> だけ使えます)