答案1
一種選擇是您\marginnote
使用marginnote
包裹;使用幾何包,您可以變更marginparsep
(邊注和常規文字之間的間隔)和/或marginparwidth
為註釋保留的寬度:
\documentclass[12pt]{article}
\usepackage[marginparsep=25pt]{geometry}
\usepackage{blindtext}
\usepackage{marginnote}
\usepackage{xcolor}
\newcommand\KeyWord[1]{%
\marginnote{\parbox[t]{\marginparwidth}{\raggedright\small \textcolor{red}{#1}}}}
\reversemarginpar
\begin{document}
\KeyWord{Key note}\blindtext
\end{document}
結果:
答案2
只需添加它即可。;-)
\documentclass{article}
\newcommand{\KW}[1]{%
\par % ensure vertical mode
\leavevmode % start a paragraph
{\setbox0=\lastbox}% remove the indentation box
\makebox[0pt][r]{\textbf{#1}\hspace{2em}}% print the keyword
\hspace*{\parindent}% add the parindent
\ignorespaces
}
\begin{document}
This paragraph has no keyword, it has some boring text just to
make it wrap across a couple of lines.
\KW{key word}
This paragraph has a keyword, it has some boring text just to
make it wrap across a couple of lines.
\end{document}
答案3
這是一個鍵值接口,允許您調整分配sep
、font
和color
:
\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{xcolor,xkeyval}
\makeatletter
\define@cmdkey{KW}{sep}{}
\define@cmdkey{KW}{color}{}
\define@cmdkey{KW}{font}{}
\newcommand{\KeyWord}[2][]{%
\par\noindent
\setkeys{KW}{#1}%
\makebox[0pt][r]{\textcolor{\cmdKV@KW@color}{\cmdKV@KW@font #2}\hspace*{\cmdKV@KW@sep}}%
\hspace*{\parindent}\ignorespaces
}
\makeatother
\newcommand{\KeyWordsetup}[1]{\setkeys{KW}{#1}}%
\AtBeginDocument{\KeyWordsetup{font=\bfseries,color=red,sep=\marginparsep}}% defaults
\begin{document}
\KeyWord{Key note}\lipsum[1]
\KeyWord[sep=20pt]{Key Note}\lipsum[2]
\KeyWord[font=\itshape,color=blue!50]{KEY NOTE}\lipsum[3]
\KeyWordsetup{font=\slshape,color=red,sep=\marginparsep}%
\KeyWord{Key note}\lipsum[4]
\end{document}