标题在左上方

标题在左上方

我正在尝试创造一个mdframed环境

  1. 标题在每一页上重复(适用于repeatframetitle
  2. 标题相对于正常文本左对齐,这意味着左行应该从标题下方开始。

有人能帮我解决 2 吗?我该如何删除这条线?以及如何摆脱丑陋10.4pt

\documentclass[parskip=half-]{scrartcl}
\usepackage{lipsum}
\usepackage[framemethod=tikz]{mdframed}


\newmdenv
  [leftmargin=0pt,
  topline=false,rightline=false,
  frametitle={\hspace{-10.4pt}I want the title here and no line beside it},
  repeatframetitle=true,
  everyline=true
  ]{test}


\begin{document}

\lipsum[1]


\begin{test}
\lipsum\lipsum
\end{test}

\end{document}

答案1

如果tcolorbox是有效选项你可以尝试

\documentclass[parskip=half-]{scrartcl}
\usepackage{lipsum}

\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,hooks}

\tcbset{%
% Title boxes will be added with overlays
  mytitle/.code={%
    \ifstrempty{#1}{}{\pgfkeysalso{%
        top=\baselineskip,
        overlay unbroken and first app = {%
        \node[rectangle, inner sep=0pt, outer sep=0pt,  
              anchor=south west,font=\bfseries]
         at (frame.north west)%
        {\strut#1};},
        overlay middle and last app = {%
        \node[rectangle, inner sep=0pt, outer sep=0pt,  
              anchor=south west,font=\bfseries]
         at (frame.north west)%
        {\strut#1};},
       enlarge top by = \baselineskip,
       enlarge top at break by= 0mm,
    }}},
}

\newtcolorbox{test}[1]{
    breakable, enhanced,%
    frame hidden, interior hidden, segmentation hidden,
    boxsep=0mm, right=0mm, rightrule=0mm, % aligns text to the right
    overlay unbroken={\draw (frame.north west)|-(frame.south east);},
    overlay first={\draw (frame.north west)|-(frame.south east);},
    overlay middle={\draw (frame.north west)|-(frame.south east);},
    overlay last={\draw (frame.north west)|-(frame.south east);},
    mytitle={#1}
    }

\begin{document}

\lipsum[1]


\begin{test}{I want the title here and no line beside}
\lipsum\lipsum
\end{test}

\end{document}

答案2

mdframed一种可能性是使用的节点(O)(左下角)和(P)(右上角)手动绘制线条,并将标题放在上方的节点(O |- P)(左上角)中。(这framemethod=tikz仅适用于。)

然后需要为 、 和 提供适当singleextrafirstextra定义:middleextrasecondextra

\documentclass[parskip=half-]{scrartcl}
\usepackage{lipsum}
\usepackage[framemethod=tikz]{mdframed}
\newcommand*\testtitle{I want the title here and no line beside it}
\tikzset{
  testtitle/.style={
    anchor = south west,
    font = \bfseries,
    inner xsep = 0pt, outer xsep = 0pt, % align the text really at the left
    outer ysep = .5ex,
    overlay % necessary to avoid http://tex.stackexchange.com/q/114829/5049
  }
}
\mdfdefinestyle{test}{
  leftmargin = 0pt,
  skipabove = 5ex, % enough space for the title node to be placed
  hidealllines = true,
  singleextra={
    \draw (O |- P) node[testtitle] {\testtitle} -- (O) -- (P |- O) ;
  },
  firstextra={
    \draw (O |- P) node[testtitle] {\testtitle} -- (O);
  },
  middleextra={
    \draw (O |- P) node[testtitle] {\testtitle} -- (O);
  },
  secondextra={
    \draw (O |- P) node[testtitle] {\testtitle} -- (O) -- (P |- O);
  }
}

\newmdenv[style=test]{test}

\begin{document}

\lipsum[1]

\begin{test}
\lipsum\lipsum
\end{test}

\end{document}

在此处输入图片描述

相关内容