![使用 floats 套件和 newenvironment 命令重新調整自訂環境定義的用途:卡在標題名稱定義上](https://rvso.com/image/420756/%E4%BD%BF%E7%94%A8%20floats%20%E5%A5%97%E4%BB%B6%E5%92%8C%20newenvironment%20%E5%91%BD%E4%BB%A4%E9%87%8D%E6%96%B0%E8%AA%BF%E6%95%B4%E8%87%AA%E8%A8%82%E7%92%B0%E5%A2%83%E5%AE%9A%E7%BE%A9%E7%9A%84%E7%94%A8%E9%80%94%EF%BC%9A%E5%8D%A1%E5%9C%A8%E6%A8%99%E9%A1%8C%E5%90%8D%E7%A8%B1%E5%AE%9A%E7%BE%A9%E4%B8%8A.png)
我正在創建一個自定義浮動來容納一長串單字和定義,我可以用它來組織,\multicols{n}
而不是使用table
or tabular
(或它們的任何派生詞),以便它可以根據定義的數量和定義的數量在頁面之間很好地流動。但是,與其他浮動環境一樣,如果它們非常大,它們將拒絕跨多個頁面流動,而我想要的是列表從我將其放置在文檔中的任何位置開始並繼續直到完成,無論可能有多少頁。
在我的谷歌搜尋過程中,我發現了這個問題:演算法標籤和分頁符,其中一個答案包括定義一個自訂環境,breakablealgorithm
這允許它們分佈在多個頁面上。
我把這段程式碼調整到我的文件中,到目前為止,我已經讓一切都按照我想要的方式工作了,除了我無法弄清楚如何打破原始程式碼的連結到演算法出現在標題中的名稱並將其連接到我的新名稱:奧爾達爾斯蒂(單字表)。我想我知道哪一行是罪魁禍首(請參閱MWE),但我無法找到如何修改它以調用我的新環境的名稱(奧爾達爾斯蒂對於\begin{bigwordlist}
和\endbigwordlist
)。
微量元素:
\documentclass[12pt]{book}
\usepackage[LY1,T1]{fontenc}
\usepackage[icelandic]{babel}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{float}
\usepackage{algorithm} % if I delete this it breaks at \caption
\floatstyle{plain}
\newfloat{wordlist}{tbhp}{lol}[chapter]
\floatname{wordlist}{Orðalisti}
\makeatletter
\newenvironment{bigwordlist}
{
\refstepcounter{wordlist}
\renewcommand{\caption}[2][\relax]{
{\center{\ALG@name~\thewordlist}{:} ##2\par}% problematic line
\ifx\relax##1\relax
\addcontentsline{lol}{wordlist}{\protect\numberline{\thewordlist}##2}
\else
\addcontentsline{lol}{wordlist}{\protect\numberline{\thewordlist}##1}
\fi
}
}{
}
\makeatother
\begin{document}
\chapter{List chapter}
This is a short list:
\begin{wordlist}
\sffamily
Master cleanse edison \\ bulb bicycle rights ad \\ affogato ethical \\ Truffaut mustache fugiat \\ skateboard shaman man braid \\
\rmfamily
\label{listi:short}
\caption{this is a short list}
\end{wordlist}
This is a very long list that I have:
\begin{bigwordlist}
\begin{footnotesize}
\begin{multicols}{2}
\sffamily
\noindent
Master cleanse edison \\ bulb bicycle rights ad \\ affogato ethical \\ Truffaut mustache fugiat \\ skateboard shaman man braid \\
tumeric irure sunt \\ enamel pin \\ in taiyaki \\ Tacos velit four\\ loko listicle health \\ goth narwhal \\ XOXO \\ esse mumblecore ea \\
bitters +1 \\ Organic sartorial authentic \\ waistcoat officia \\ reprehenderit pork \\ belly helvetica mumblecore \\ Chillwave dreamcatcher marfa \\
ea artisan kickstarter \\ thundercats \\ lo-fi tofu \\ before they sold out \\ air plant \\ woke offal \\ Typewriter truffaut quinoa \\
everyday carry \\ ethical narwhal in \\ Selfies la croix \\ cray salvia subway tile \\ bitters vexillologist \\ enim tumeric anim \\ Craft beer \\
meh lorem \\ air plant \\ adaptogen stumptown \\ cold-pressed chartreuse\\ deserunt chicharrones forage \\ Lomo cupidatat \\ subway tile \\
locavore ut \\ 90's keffiyeh ramps \\ consectetur truffaut \\ skateboard \\ pour-over slow-carb \\ irony subway \\ tile adipisicing aliquip \\
Yuccie vinyl shoreditch \\ mumblecore \\ sriracha \\ tote bag \\ heirloom gluten-free wayfarers \\ letterpress glossier \\ Green juice taiyaki \\
chambray actually \\ letterpress \\ XOXO lyft \\ duis af sed \\ flannel \\ gentrify deep v. Dreamcatcher \\ cornhole flexitarian \\ mumblecore street art\\
raw denim \\ Live-edge \\ vegan portland \\ cray et yuccie \\ beard \\ shabby chic qui \\ selvage roof party \\ sunt \\ Pour-over yr \\ mollit raclette \\
beard brooklyn \\ hell of hexagon pork belly celiac \\ Succulents chambray\\ incididunt coloring book \\ disrupt flexitarian taiyaki sed \\ Before they sold out \\
edison bulb \\ prism \\ farm-to-table \\ do coloring book \\ Tattooed lorem \\ cred tacos \\ before they sold out \\ viral \\ man bun \\ cray enamel \\
pin wolf \\ Tofu wolf\\ semiotics id typewriter \\ XOXO \\ you probably haven't heard of them \\ tote bag \\ williamsburg \\ Asymmetrical heirloom \\
taxidermy cred \\ ea occaecat squid \\ fugiat labore \\ PBR\&B godard \\ the end
\rmfamily
\end{multicols}
\end{footnotesize}
\label{listi:long}
\caption{this is a long list}
\end{bigwordlist}
\listof{wordlist}{Orðalistaskrá}
\end{document}
關於創建新型浮動環境的一些評論和答案說人們應該使用 packagenewfloat
而不是float
,並且我嘗試用它來設定相同類型的環境。但是,我仍然需要定義一個可破壞的版本,因為我看不到我可以在其中實現開箱即用的分頁功能。
答案1
使用\fname@wordlist
而不是\ALG@name
.那你也不再需要了\usepackage{algorithm}
。
\documentclass[12pt]{book}
\usepackage[LY1,T1]{fontenc}
\usepackage[icelandic]{babel}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{float}
\floatstyle{plain}
\newfloat{wordlist}{tbhp}{lol}[chapter]
\floatname{wordlist}{Orðalisti}
\makeatletter
\newenvironment{bigwordlist}
{
\refstepcounter{wordlist}
\renewcommand{\caption}[2][\relax]{
{\center{\fname@wordlist~\thewordlist}{:} ##2\par}% problematic line
\ifx\relax##1\relax
\addcontentsline{lol}{wordlist}{\protect\numberline{\thewordlist}##2}
\else
\addcontentsline{lol}{wordlist}{\protect\numberline{\thewordlist}##1}
\fi
}
}{
}
\makeatother
\begin{document}
\chapter{List chapter}
This is a short list:
\begin{wordlist}
\sffamily
Master cleanse edison \\ bulb bicycle rights ad \\ affogato ethical \\ Truffaut mustache fugiat \\ skateboard shaman man braid \\
\rmfamily
\label{listi:short}
\caption{this is a short list}
\end{wordlist}
This is a very long list that I have:
\begin{bigwordlist}
\begin{footnotesize}
\begin{multicols}{2}
\sffamily
\noindent
Master cleanse edison \\ bulb bicycle rights ad \\ affogato ethical \\ Truffaut mustache fugiat \\ skateboard shaman man braid \\
tumeric irure sunt \\ enamel pin \\ in taiyaki \\ Tacos velit four\\ loko listicle health \\ goth narwhal \\ XOXO \\ esse mumblecore ea \\
bitters +1 \\ Organic sartorial authentic \\ waistcoat officia \\ reprehenderit pork \\ belly helvetica mumblecore \\ Chillwave dreamcatcher marfa \\
ea artisan kickstarter \\ thundercats \\ lo-fi tofu \\ before they sold out \\ air plant \\ woke offal \\ Typewriter truffaut quinoa \\
everyday carry \\ ethical narwhal in \\ Selfies la croix \\ cray salvia subway tile \\ bitters vexillologist \\ enim tumeric anim \\ Craft beer \\
meh lorem \\ air plant \\ adaptogen stumptown \\ cold-pressed chartreuse\\ deserunt chicharrones forage \\ Lomo cupidatat \\ subway tile \\
locavore ut \\ 90's keffiyeh ramps \\ consectetur truffaut \\ skateboard \\ pour-over slow-carb \\ irony subway \\ tile adipisicing aliquip \\
Yuccie vinyl shoreditch \\ mumblecore \\ sriracha \\ tote bag \\ heirloom gluten-free wayfarers \\ letterpress glossier \\ Green juice taiyaki \\
chambray actually \\ letterpress \\ XOXO lyft \\ duis af sed \\ flannel \\ gentrify deep v. Dreamcatcher \\ cornhole flexitarian \\ mumblecore street art\\
raw denim \\ Live-edge \\ vegan portland \\ cray et yuccie \\ beard \\ shabby chic qui \\ selvage roof party \\ sunt \\ Pour-over yr \\ mollit raclette \\
beard brooklyn \\ hell of hexagon pork belly celiac \\ Succulents chambray\\ incididunt coloring book \\ disrupt flexitarian taiyaki sed \\ Before they sold out \\
edison bulb \\ prism \\ farm-to-table \\ do coloring book \\ Tattooed lorem \\ cred tacos \\ before they sold out \\ viral \\ man bun \\ cray enamel \\
pin wolf \\ Tofu wolf\\ semiotics id typewriter \\ XOXO \\ you probably haven't heard of them \\ tote bag \\ williamsburg \\ Asymmetrical heirloom \\
taxidermy cred \\ ea occaecat squid \\ fugiat labore \\ PBR\&B godard \\ the end
\rmfamily
\end{multicols}
\end{footnotesize}
\label{listi:long}
\caption{this is a long list}
\end{bigwordlist}
\listof{wordlist}{Orðalistaskrá}
\end{document}