4

I get many times things that are somehow related to the main topic and should be separated by blue background, for instance.

I do at the moment only

\documentclass{article}
\newtheorem{theorem}{Theorem}
\newtheorem{question}[theorem]{Question}
\begin{document}
\begin{question}
Lorem ipsum?
\end{question}
\end{document}

I get like this

enter image description here

where the question -environment only adds the question mark to the front. I think there is some problem because the environment should be numbered, first of all.

How can you make distinguish the question environment better?

1 Answers1

6

There are many ways, and it all depends on the desired final layout. Below, two options: one using the standard quote environment; the other one using mdframed:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newmdenv[linecolor=cyan,backgroundcolor=cyan!20]{question}

\begin{document}

\lipsum[2]
\begin{quote}
\lipsum[2]
\end{quote}
\lipsum[2]
\begin{question}
\lipsum[2]
\end{question}
\lipsum[2]

\end{document}

enter image description here

And with tcolorbox:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\usepackage{lipsum}

\newtcolorbox{question}{breakable,colframe=cyan,colback=cyan!20}

\begin{document}

\lipsum[2]
\begin{question}
\lipsum[2]
\end{question}
\lipsum[2]

\end{document}

enter image description here

Another option using a list through changepage:

\documentclass{article}
\usepackage{changepage}
\usepackage{lipsum}

\newenvironment{question}
  {\par\smallskip\begin{adjustwidth}{1em}{1em}\small\itshape}
  {\end{adjustwidth}\par\smallskip}

\begin{document}

\lipsum[2]
\begin{question}
\lipsum[2]
\end{question}
\lipsum[2]

\end{document}

enter image description here

The options using mdframed and tcolorbox offer you many customization possibilities; please refer to the documentation of the packages.

For example, you can define your structure as a theorem-like block using, for example, amsthm and then surround it with a mdframed:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{amsthm}
\usepackage{lipsum}

\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\begin{document}

\lipsum[2]
\begin{question}
\lipsum[2]
\end{question}
\lipsum[2]

\end{document}

enter image description here

A numbered structure with tcolorbox:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtcolorbox[auto counter]
  {question}
  {colback=cyan!20,colframe=cyan,fonttitle=\bfseries,
  title=Question~\thetcbcounter}

\begin{document}

\lipsum[2]
\begin{question}
\lipsum[2]
\end{question}
\lipsum[2]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thank you very much for your clear answer! I like most the last proposal with mdframed and tcolor box because of cusmotisation possibilities. – Léo Léopold Hertz 준영 Feb 20 '14 at 19:48
  • I like your update now most (the last option with numbered structure). :) – Léo Léopold Hertz 준영 Feb 20 '14 at 19:49
  • Do you need to add some specific number, like [1], in the command? I get these errors https://dl.dropboxusercontent.com/u/62073194/Screen%20Shot%202014-02-20%20at%2022.01.33.png May be complications of my other commands. – Léo Léopold Hertz 준영 Feb 20 '14 at 20:03
  • 1
    @Masi No, no need to add anything else in my examples; looking at the error messages, it seems that you are using an old version of tcolorbox. I am using version 2.70 (2014/02/06). – Gonzalo Medina Feb 20 '14 at 20:05
  • I put this "\listfiles" to my preamble, but I did not find log file in the same directory (not sure where it goes). I am using the newest OSX with MacTex. My installation is from 2013. – Léo Léopold Hertz 준영 Feb 20 '14 at 21:40
  • @Masi The list of files and versions goes to the .log file (which should be in the same directory as the .tex), but italso gets output to the console. Notice that eventhough your installation is from 2013, the tcolorbox has suffered several updates (the version I use is a few days old only). – Gonzalo Medina Feb 20 '14 at 21:43
  • @Masi If you still experience problems, let me know and I can give you a similar version but with mdframed. – Gonzalo Medina Feb 20 '14 at 22:18
  • I tried the second to last with mdframed. The numbering does not work for some reason: I see like this https://dl.dropboxusercontent.com/u/62073194/Screen%20Shot%202014-02-21%20at%2017.59.48.png How can you set the numbering? It can be a bug with my versions of the software. – Léo Léopold Hertz 준영 Feb 21 '14 at 16:01
  • @Masi can you post elsewhere the code you used with mdframed? Just a simple document (like the ones in my answers) showing only the relevant settings and allowing me to reproduce the undesired bahaviour? – Gonzalo Medina Feb 21 '14 at 23:22
  • I managed to find the bug which caused the question marks. I used the braces with tkiz in some part of my code. It requires the package unicode-math. I just removed unicode-math. Can you use tkiz with braces without unicode-math package? – Léo Léopold Hertz 준영 Feb 22 '14 at 14:30
  • @Masi I don't understand your question. What do you mean by "use tkiz with braces"? Please consider opening a follow-up question. – Gonzalo Medina Feb 22 '14 at 14:34
  • @ I added the package to the body of the question because I used it for the screenshot. – Léo Léopold Hertz 준영 Feb 22 '14 at 14:42
  • @Masi please, don't do that. The original question had nothing to do with this. As I said, consider opening a new question and please roll-back the edit; otherwise, it might be confusing for someone reading the question. – Gonzalo Medina Feb 22 '14 at 14:47
  • 1
    Thank you for your feedback! I opened a new question here http://tex.stackexchange.com/questions/161809/why-unicode-math-not-working-with-tikz – Léo Léopold Hertz 준영 Feb 22 '14 at 14:55
  • Extension to Gonzalo's answer. The bug of missing numbering (marked by question marks) was because of this line \usepackage{unicode-math} % This causes bugs tbox environment – Léo Léopold Hertz 준영 Feb 22 '14 at 14:29