用乳胶制作的日记,侧面有附加注释

用乳胶制作的日记,侧面有附加注释

我正在尝试制作一个具有以下格式的日记

  1. 每个条目将放在一个彩色框内
  2. 每个条目都有一个包含日期的标题和一个可选标题
  3. 我希望能够在条目的特定行的侧面(最好是在右侧)添加注释。注释将放在单独的彩色框中。

我搜索了tex.se并找到了两个代码来实现这一点。第一个来自 Gonzalo Medina 的回答为边注创建一个框架环境

他的方法是在左侧输入注释,但我认为如果注释在右侧会更好。

对于 1 和 2,我认为费拉赫费扎给出了一个很好的答案使用 Latex 记日记然而,有些点不起作用,因为他可能遗漏了很多代码。

这个想法是有一个diary.tex(包含定义的newenvironment)文件,该文件将被输入到主文件中。

我的最终输出将是这两个的组合

在此处输入图片描述

我的代码是

diary.tex

\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}
\newenvironment{diary}[2]
{\par\medskip\refstepcounter{diary}%
\hbox{%
\fboxsep=\the\sidebar\hspace{-\envborder}\hspace{-.5\sidebar}%
\colorbox{orange}{%
\hspace{\envborder}\footnotesize\sffamily\bfseries%
\textcolor{white}{{#1}\ {#2}\enspace\thediary\hspace{\envborder}}
%\today % Print date in header of frame
}}}{\vspace{0.5cm}}

main file以下是

\documentclass{article}

\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{marginnote}
\usetikzlibrary{calc}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{framed}
\usepackage{datetime}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}

\reversemarginpar

\newsavebox\mybox
\newlength\BoxHt

\newcommand\caution[2][-2.2\baselineskip]{%
\begin{lrbox}{\mybox}
\parbox{\marginparwidth}{#2}
\end{lrbox}%
\settoheight\BoxHt{\usebox\mybox}%
\raisebox{\BoxHt}[0pt][0pt]{\marginnote{%
  \begin{mdframed}[
    userdefinedwidth=\marginparwidth,
    innerleftmargin=3pt,
    innerrightmargin=3pt,
    linecolor=BrickRed,
    frametitle=\colorbox{white}{\space Caution\space},
    frametitlefont=\color{BrickRed}\sffamily,
    innertopmargin=10pt,
    frametitleaboveskip=-\ht\strutbox,
    frametitlebelowskip=-\ht\strutbox,
    frametitlealignment=\raggedright,
    singleextra={\fill[BrickRed] let \p1=(P), \p2=(O)  in 
    ( $ (P|-0,0.5*\y2+0.5*\y1) + (0,-4pt) $ ) -- +(4pt,4pt) -- +(0,8pt) -- cycle;}
]\RaggedRight\small#2\end{mdframed}}[#1]}}


\input{diary}


\begin{document}

\begin{diary}{}{14.07.2013}
\lipsum*[3-4]\caution{\lipsum[2]}\lipsum[3-5]
\end{diary}

Some test text\caution{Some text goes here just to illustrate the command}

\lipsum[4-5].\caution{Not forget to do this} This is a line that really needs some caution. But now it's time to move on to the next paragraph. \lipsum[1]

\end{document}

我的输出如下

在此处输入图片描述

如何达到期望的输出?

编辑

mdframed我尝试使用带有 3 个参数的新命令来实现彩色背景\note。新命令diary.tex

\mdfdefinestyle{MyFrameBlue}{%
    linecolor=blue!20!white,
    outerlinewidth=0pt,
    roundcorner=0pt,
    innertopmargin=-15pt,
    innerbottommargin=-5pt,
    innerrightmargin=0pt,
    innerleftmargin=0pt,
    backgroundcolor=blue!20!white}
\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}
\newenvironment{diary}[2]
{\par\medskip\refstepcounter{diary}%
\hbox{%
\setlength{\fboxsep}{5pt}
\colorbox{orange}{%
\hspace{2pt}\footnotesize\sffamily\bfseries%
\textcolor{white}{\thediary. \ {#1}\ {#2}\enspace\hspace{2pt}}
}}}{\vspace{0.5cm}}
\newcommand{\note}[3]{\begin{mdframed}[style=MyFrameBlue]
                          \begin{diary}{#1}{#2}{\vspace{0.5cm} #3}\end{diary}
                      \end{mdframed}
                      }

问题是,当我在环境\caution{}内部使用时diary,会采用背景颜色。

\note{}{14.11.2013}{This is the \caution{Watch the traps!} first note}

在此处输入图片描述

答案1

费拉赫费扎更新了他的回答使用 Latex 记日记diary.tex像这样更新

diary.tex

 \newlength\sidebar
 \newlength\envrule
 \newlength\envborder
 \setlength\sidebar{1.5mm}
 \setlength\envrule{0.4pt}
 \setlength\envborder{2mm}

\makeatletter
 \long\def\fboxs#1{%
   \leavevmode
   \setbox\@tempboxa\hbox{%
     \color@begingroup
       \kern\fboxsep{#1}\kern\fboxsep
     \color@endgroup}%
   \@frames@x\relax}
 \def\frameboxs{%
   \@ifnextchar(%)
     \@framepicbox{\@ifnextchar[\@frameboxs\fboxs}}
 \def\@frameboxs[#1]{%
   \@ifnextchar[%]
     {\@iframeboxs[#1]}%
     {\@iframeboxs[#1][c]}}
 \long\def\@iframeboxs[#1][#2]#3{%
   \leavevmode
   \@begin@tempboxa\hbox{#3}%
     \setlength\@tempdima{#1}%
     \setbox\@tempboxa\hb@xt@\@tempdima
          {\kern\fboxsep\csname bm@#2\endcsname\kern\fboxsep}%
     \@frames@x{\kern-\fboxrule}%
   \@end@tempboxa}
 \def\@frames@x#1{%
   \@tempdima\fboxrule
   \advance\@tempdima\fboxsep
   \advance\@tempdima\dp\@tempboxa
   \hbox{%
     \lower\@tempdima\hbox{%
       \vbox{%
         %\hrule\@height\fboxrule
         \hbox{%
          \vrule\@width\fboxrule
           #1%
           \vbox{%
             \vskip\fboxsep
             \box\@tempboxa
             \vskip\fboxsep}%
           #1%
           }%\vrule\@width\fboxrule}%
         }%\hrule\@height\fboxrule}%
                           }%
         }%
 }
 \def\esefcolorbox#1#{\esecolor@fbox{#1}}
 \def\esecolor@fbox#1#2#3{%
   \color@b@x{\fboxsep\z@\color#1{#2}\fboxs}{\color#1{#3}}}
 \makeatother


 \definecolor{exampleborder}{HTML}{FE642E}
 \definecolor{examplebg}{HTML}{CEF6EC}
 \definecolor{statementborder}{rgb}{.9,0,0}
 \definecolor{statementbg}{rgb}{1,1,1}

 \newenvironment{eseframed}{%
   \def\FrameCommand{\fboxrule=\the\sidebar  \fboxsep=\the\envborder%
   \esefcolorbox{exampleborder}{examplebg}}%
   \MakeFramed{\FrameRestore}}%
  {\endMakeFramed}

\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}

 %%% CODE ENVIRONMENT. PUT TEXT INTO COLORED FRAME %%%
 \newenvironment{diary}[2]
 {\par\medskip\refstepcounter{diary}%
 \hbox{%
 \fboxsep=\the\sidebar\hspace{-\envborder}\hspace{-.5\sidebar}%
 \colorbox{exampleborder}{%
 \hspace{\envborder}\footnotesize\sffamily\bfseries%
 \textcolor{white}{{#1}\ {#2}\enspace\hspace{\envborder}}
 }
 }
 \nointerlineskip\vspace{-\topsep}%
 \begin{eseframed}\noindent\ignorespaces%
 }
 {\end{eseframed}\vspace{-\baselineskip}\medskip}

在里面main.tex 贡萨洛梅迪纳将会添加代码,它将在彩色框内给出带有指向箭头的旁注。

\documentclass{article}

\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{marginnote}
\usetikzlibrary{calc}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{framed}
\usepackage{datetime}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}

\reversemarginpar

\newsavebox\mybox
\newlength\BoxHt

\newcommand\caution[2][-2.2\baselineskip]{%
\begin{lrbox}{\mybox}
\parbox{\marginparwidth}{#2}
\end{lrbox}%
\settoheight\BoxHt{\usebox\mybox}%
\raisebox{\BoxHt}[0pt][0pt]{\marginnote{%
  \begin{mdframed}[
    userdefinedwidth=\marginparwidth,
    innerleftmargin=3pt,
    innerrightmargin=3pt,
    linecolor=BrickRed,
    frametitle=\colorbox{white}{\space Caution\space},
    frametitlefont=\color{BrickRed}\sffamily,
    innertopmargin=10pt,
    frametitleaboveskip=-\ht\strutbox,
    frametitlebelowskip=-\ht\strutbox,
    frametitlealignment=\raggedright,
    singleextra={\fill[BrickRed] let \p1=(P), \p2=(O)  in 
    ( $ (P|-0,0.5*\y2+0.5*\y1) + (0,-4pt) $ ) -- +(4pt,4pt) -- +(0,8pt) -- cycle;}
]\RaggedRight\small#2\end{mdframed}}[#1]}}


\input{diary}

\begin{document}

\begin{diary}{}{14.07.2013}
\lipsum*[3-4]\caution{\lipsum[2]}\lipsum[3-5]
\end{diary}

\end{document}

输出为

在此处输入图片描述

相关内容