2

enter image description here How to create this type of example box? Thank you!

2
  • with tcolorbox or mdframed.
    – Ignasi
    Mar 8, 2017 at 17:58
  • 1
    I would say: Typical tcolorbox environment...
    – user31729
    Mar 8, 2017 at 18:03

2 Answers 2

3

A possibility is the usage of tcolorbox like this:

\documentclass[11pt]{standalone}

\usepackage{tcolorbox}

\newcommand{\myexample}[2]{
    \begin{tcolorbox}[colback=black!5!white,colframe=black,title={Example: #1}]
        #2
    \end{tcolorbox}
}

\begin{document}
\myexample{test}{This is just a test}
\end{document}

The result of above code

To get something which looks more like the example image provided (thanks to Christian Hupfer) you could use:

\documentclass[11pt]{standalone}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcommand{\myexample}[2]{
    \begin{tcolorbox}[enhanced,colback=black!5!white,colframe=black,sharp corners,title={Example: #1}]
        #2
    \end{tcolorbox}
}

\begin{document}
\myexample{test}{This is just a test}
\end{document}

Which results in:

result of second code snippet

8
  • 1
    With skins library, the enhanced and `sharp corners, it would even look more like the example in the O.P. screen shot
    – user31729
    Mar 8, 2017 at 18:38
  • @ChristianHupfer I never used sharp corners, thanks for the tip. I don't think OP needs something that looks just like the example because the question was how to create this type of boxes. Feedback from OP might help here.
    – Skillmon
    Mar 8, 2017 at 18:40
  • @ChristianHupfer I've added the changes you suggested in a second code snippet.
    – Skillmon
    Mar 8, 2017 at 18:57
  • @Duy if this answer satisfies your needs you should accept it.
    – Skillmon
    Mar 9, 2017 at 19:39
  • @skillmon I use \documentclass{dmathesis} so it can not run the code. It appears "Can be only used in preamble". Could you help me fix it?
    – Duy
    Apr 12, 2017 at 6:31
1

Another possibility would be to use a table to do something like this...

Code:

\documentclass{amsart}
\usepackage{lipsum}
\usepackage[table]{xcolor}
\usepackage{color}
\usepackage{array}
\begin{document}

\begin{table}[htp]
    \begin{tabular}{|cp{5in}c|}
    \hline
\cellcolor{black!100}&\multicolumn{1}{p{5in}}{\cellcolor{black!100}{\color{white}\Large{Some Title Here...}}}&\cellcolor{black!100}\\\hline
         &\vskip .01in \lipsum[1]&
    \end{tabular}
    \end{table}
\end{document}

Yields:

enter image description here

3
  • Why do you define more columns than necessary? If you just want extra space you can get that using: \begin{tabular}{|@{\hspace{1em}}p{5in}@{\hspace{1em}}|}
    – Skillmon
    Mar 8, 2017 at 18:32
  • @Skillmon You are quite right, except that in this case doing that results in the top cell having white strips on both sides. Where it should be black.
    – Dan
    Mar 8, 2017 at 18:33
  • I just realised that. There might be a hacky way to get those, though :)
    – Skillmon
    Mar 8, 2017 at 18:45

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.