2 Answers
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}
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:
-
1With
skins
library, theenhanced
and `sharp corners, it would even look more like the example in the O.P. screen shot– user31729Mar 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.– SkillmonMar 8, 2017 at 18:40
-
@ChristianHupfer I've added the changes you suggested in a second code snippet.– SkillmonMar 8, 2017 at 18:57
-
-
@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?– DuyApr 12, 2017 at 6:31
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:
-
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}}|}
– SkillmonMar 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.– DanMar 8, 2017 at 18:33
-
I just realised that. There might be a hacky way to get those, though :)– SkillmonMar 8, 2017 at 18:45
tcolorbox
ormdframed
.tcolorbox
environment...