2

My codes are follows:

   \documentclass{book}
\usepackage{xcolor,mdframed}
\usepackage{showframe}
\begin{document}

\setlength{\marginparwidth}{2pc}

\newenvironment{codebox}{%
     \color{blue}%
   }{}%
\surroundwithmdframed[
  skipabove=\baselineskip,
  hidealllines=true,leftmargin=-24pt,innerleftmargin=-24pt,
  backgroundcolor=black!10,
]{codebox}

\begin{codebox}
All code snippets %\marginpar{MS:74} 
in the book are set aside and appear like this.  They
will show some minimal code for purposes of illustration.  For example,
this is how to compute the cosine of a sequence of numbers:
\begin{verbatim}
>>> import numpy as np
>>> x = np.random.random(100)  # 100 numbers between 0 and 1
>>> cos_x = np.cos(x)  # cosine of each element.

\end{verbatim}
For more details on the essential modules for scientific computing
in Python, see appendix~\ref{app:python_tutorial}.
\end{codebox}

\end{document}

I got the output as:

enter image description here

I need to extend the gray shade upto the extreme left side of the text, is it possible? please advise...

  • @muxoveji sorry, it was updated...thanks for your notification.... – MadyYuvi May 23 at 11:00
2

Put leftmargin and innerleftmargin to 0pt, and the problem is solved. I hope to have solve your problem and especially of to have understood your request. Excuse me for my always bad English.

enter image description here

\documentclass{book}
\usepackage{xcolor,mdframed}
\usepackage{showframe}
\begin{document}

\setlength{\marginparwidth}{2pc}
\newenvironment{codebox}{%
     \color{blue}%
   }{}%
\surroundwithmdframed[
  skipabove=\baselineskip,
  hidealllines=true,
  leftmargin=0pt,
  innerleftmargin=0pt,
  backgroundcolor=black!10,
]{codebox}
\begin{codebox}
All code snippets %\marginpar{MS:74} 
in the book are set aside and appear like this. They
will show some minimal code for purposes of illustration.  For example,
this is how to compute the cosine of a sequence of numbers:
\begin{verbatim}
>>> import numpy as np
>>> x = np.random.random(100)  # 100 numbers between 0 and 1
>>> cos_x = np.cos(x)  # cosine of each element.
\end{verbatim}
For more details on the essential modules for scientific computing
in Python, see appendix\ldots.
\end{codebox}
\end{document}

If you want to move the whole thing to the left, add geometry package, namely \usepackage[left=.5in]{geometry}.

enter image description here

  • Much thanks for your valuable suggestion, but I need the text should have some indent (12pt) from the left and rightside rule... – MadyYuvi Jun 10 at 4:39
  • @MadyYuvi Always available. Then I did not understand how many times the question. If you want to remove my answer. There are no problems. Greetings. – Sebastiano Jun 10 at 21:41
  • My sincere apologies..., not able to understand correctly what you mentioned...do you need more clarification of my request? If yes, I'll rephrase my question with more clarification...(I know you are one of a LaTeX great ...) – MadyYuvi Jun 11 at 4:43
  • @MadyYuvi Ahhahaah :-). No no, I'm only a humble man...No apologies ok? :-) A great huge. – Sebastiano Jun 12 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.