2010-08-02 11 views
5

Questa è una domanda di follow-up chiesto here. Ho bisogno di creare una scatola grigiastra rotonda come mostrato.Come rendere la casella grigio-tutto l'utilizzo tiks

http://img707.imageshack.us/img707/9705/screenshot20100718at913.png

Sulla base delle risposte, ho provato qualcosa, ma non così fruttuoso. Quindi, arrivano altre domande.

mi si avvicinò con il seguente comando, ma non funziona. Il verbo all'interno del minipage non viene compilato.

 
\newcommand{\graybox}[1]{% 
\noindent\begin{tikzpicture}% 
    \draw node[draw=black,fill=black!10,rounded corners,inner sep=2ex,text width=\mytikzwidth] {% 
    #1 
    };% 
\end{tikzpicture}% 
}% 

%% ERROR - verbatim doesn't work. 
\graybox{% 
\begin{minipage}[b]{\mytikzwidth} 
... 
\begin{verbatim} 
java -cp \$CLOJUREJAR:\$CLASSPATH clojure.lang.Script \$1 
\end{verbatim} 
... 
\end{minipage} 
} 

Ho anche provato con l'ambiente, che inoltre non funziona. Il minipage non è seduto all'interno del minipage.

 
\newenvironment{grayboxx}% 
{\noindent\begin{tikzpicture}% 
    \draw node[draw=black,fill=black!10,rounded corners,inner 
    sep=2ex,text width=\mytikzwidth] {% 
}% 
{};% 
\end{tikzpicture}% 
} 

Domande

  • Cosa c'è di sbagliato con il codice LaTeX? Come posso usare l'ambiente verbatim con minipage in tikzpicture?
  • Mi può insegnare a un modo migliore per implementare l'ambiente grayboxed come è mostrato nella foto allegata?

Questo è tutto il codice, e ho attaccato il risultato compilato con il risultato compilato.

http://a.imageshack.us/img571/7828/screenshot20100802at148.png

 
\documentclass{article} 

\usepackage{tikz} 

\newlength{\mytikzwidth} 
\setlength{\mytikzwidth}{\textwidth} 
\addtolength{\mytikzwidth}{-4ex} % this 10ex is just rule of thumb. 

\newcommand{\graybox}[1]{% 
\noindent\begin{tikzpicture}% 
    \draw node[draw=black,fill=black!10,rounded corners,inner sep=2ex,text width=\mytikzwidth] {% 
    #1 
    };% 
\end{tikzpicture}% 
}% 

\newenvironment{grayboxx}% 
{\noindent\begin{tikzpicture}% 
    \draw node[draw=black,fill=black!10,rounded corners,inner 
    sep=2ex,text width=\mytikzwidth] {% 
}% 
{};% 
\end{tikzpicture}% 
} 

\begin{document} 

%%%% CASE 1 - OK 
\begin{minipage}[b]{\mytikzwidth} 
clj command is as follows. 

\begin{verbatim} 
java -cp \$CLOJUREJAR:\$CLASSPATH clojure.lang.Script \$1 
\end{verbatim} 

hello.clj needs a namespace (ns) to let the modules know about this code. 
\end{minipage} 

%%%% CASE 2 - not working with verbatim 
\graybox{% 
\begin{minipage}[b]{\mytikzwidth} 
clj command is as follows. 

%\begin{verbatim} 
java -cp \$CLOJUREJAR:\$CLASSPATH clojure.lang.Script \$1 
%\end{verbatim} 

hello.clj needs a namespace (ns) to let the modules know about this code. 
\end{minipage} 
} 

%%%% CASE 3 - not inside the tikz 
\begin{grayboxx} 
\begin{minipage}[b]{\mytikzwidth} 
clj command is as follows. 

%\begin{verbatim} 
java -cp \$CLOJUREJAR:\$CLASSPATH clojure.lang.Script \$1 
%\end{verbatim} 

hello.clj needs a namespace (ns) to let the modules know about this code. 
\end{minipage} 
\end{grayboxx} 

\end{document} 

risposta

5

ho chiesto la stessa domanda a LaTeX Community, e ho avuto la seguente risposta da Juanjo.

http://a.imageshack.us/img821/290/screenshot20100802at706.png

 
\documentclass[a4paper]{article} 

\usepackage{tikz} 
\usepackage{lipsum} 

\newlength{\RoundedBoxWidth} 
\newsavebox{\GrayRoundedBox} 
\newenvironment{GrayBox}[1][\dimexpr\textwidth-4.5ex]% 
    {\setlength{\RoundedBoxWidth}{\dimexpr#1} 
    \begin{lrbox}{\GrayRoundedBox} 
     \begin{minipage}{\RoundedBoxWidth}}% 
    { \end{minipage} 
    \end{lrbox} 
    \begin{center} 
    \begin{tikzpicture}% 
     \draw node[draw=black,fill=black!10,rounded corners,% 
      inner sep=2ex,text width=\RoundedBoxWidth]% 
      {\usebox{\GrayRoundedBox}}; 
    \end{tikzpicture} 
    \end{center}} 

\begin{document} 

\lipsum[1] 

\begin{GrayBox} 
    clj command is as follows. 
    \begin{verbatim} 
    java -cp \$CLOJUREJAR:\$CLASSPATH clojure.lang.Script \$1 
    \end{verbatim} 
    hello.clj needs a namespace (ns) to let the modules 
    know about this code. 
\end{GrayBox} 

\lipsum[2] 

\begin{GrayBox}[0.75\textwidth] 
    clj command is as follows. 
    \begin{verbatim} 
    java -cp \$CLOJUREJAR:\$CLASSPATH 
    clojure.lang.Script \$1 
    \end{verbatim} 
    hello.clj needs a namespace (ns) to let the modules 
    know about this code. 
\end{GrayBox} 

\lipsum[3] 

\end{document}