[Tex/LaTex] How to draw a box with tcolorbox

tcolorbox

I'm trying to draw something like the following:

Code for desired effect without using tcolorbox

\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
%%------------------------------
\usepackage{lipsum}
\setlength{\parindent}{0pt}

\begin{document}

\rule{4in}{1pt}
\par
\begin{minipage}[t]{4in}
\lipsum[1]
\end{minipage}

\end{document}

enter image description here

This seems like it should be something straight-forward. But, I'm getting lost in the documentation for tcolorbox. Nothing I'm doing creates the same effect.

For example, I don't understand what the keys interior hidden or enhanced are doing or how they're interacting with each other. Why do the following create such wildly different effects:

First example using tcolorbox

\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
\setlength{\parindent}{0pt}
%%------------------------------
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum}

\begin{document}

\begin{tcolorbox}[width=4in,
                  %%enhanced,
                  %%frame hidden,
                  interior hidden,
                  boxsep=0pt,
                  left=0pt,
                  right=0pt,
                  top=2pt,
                  ]%%
  \lipsum[1]
\end{tcolorbox}

\end{document}

produces

enter image description here

Second example using tcolorbox

\begin{tcolorbox}[width=4in,
                  enhanced,
                  frame hidden,
                  interior hidden,
                  boxsep=0pt,
                  left=0pt,
                  right=0pt,
                  top=2pt,
                  ]%%
  \lipsum[1]
\end{tcolorbox}

produces

enter image description here

Third example using tcolorbox

\begin{tcolorbox}[width=4in,
                  enhanced,
                  %%frame hidden,
                  interior hidden,
                  boxsep=0pt,
                  left=0pt,
                  right=0pt,
                  top=2pt,
                  ]%%
  \lipsum[1]
\end{tcolorbox}

produces:

enter image description here

The documentation says that interior hidden is shorthand for

interior style={draw=none,fill=none}

but clearly fill=none is being ignored in the first and third examples. Why?

I've found keys such as enhancedfirst, enhancedlast, enhancedmiddle, nobeforeafter. But none of these achieve the effects that I want in terms of framing: I just want a bar across the top of the box.

Additional issues:

  1. The text is formatted differently between the minipage environment approach and the tcolorbox environment even though the widths are the same.
  2. There's a sliver of white space along the left hand side (and who knows where else) that I can't seem to get rid of from the tcolorbox environment.

Could someone please show me how to set up a tcolorbox enivornment to get the effect I want?

Best Answer

You need boxrule=0pt and toprule commands.

boxrule=0pt,toprule=1pt,

Similarly there are bottomrule leftrule and \rightrule.

\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
\setlength{\parindent}{0pt}
%%------------------------------
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum}

\begin{document}

\begin{tcolorbox}[width=4in,
                  boxsep=0pt,
                  left=0pt,
                  right=0pt,
                  top=2pt,
                  arc=0pt,
                  boxrule=0pt,toprule=1pt,
                  colback=white
                  ]%%
  \lipsum[1]
\end{tcolorbox}

\end{document}

enter image description here