به دلیل قطعی اینترنت و نبود دسترسی به ایمیل‌های خارجی، می‌توانید بدون نیاز به تایید ایمیل، ثبت‌نام کنید و پرسش‌های خود را بپرسید.

اولین بار است که به اینجا می‌آیید؟ راهنمای سایت را بخوانید!
+2 رای
3.7k بازدید

سلام. با استفاده از TikZ یک محیط تعریف کرده ایم به صورت زیر:

\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A)  at ($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at ($(pic cs:BB)+(0,-1\bs)$); 
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at  ($(A-|current page text area.east)$);
\coordinate (E) at  ($(B-|current page text area.east)$);
\coordinate (F) at  ($(B-|current page text area.west)$);
\coordinate (G) at  ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at  ($(C)+(0.5\tw,0)$);
\coordinate (I) at  ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at  ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at  ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at  ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at  ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at  ($(E)+(-0.5\tw,0)$);
\coordinate (O) at  ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at  ($(F)+(0.4\tw,-0.5\bs)$);

\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);

\end{tikzpicture}
\newenvironment{mynote}{\tikzmark{AA}}{\tikzmark{BB}}
\begin{mynote}
I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ.
\end{mynote}
\end{document}

که خروجی آن به صورت زیر است:
enter image description here
با توجه به این که از گزینه های remember picture و overlay استفاده کرده ایم می خواهیم این محیط قابل استفاده مجدد باشد و بتوانیم بارها از آن استفاده کنیم و اگر متن در اطراف آن باشد مشکلی پیش نیاید اما چنین نیست. مثلا با کد زیر مشکل پیش می آید.

\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A)  at ($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at ($(pic cs:BB)+(0,-1\bs)$); 
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at  ($(A-|current page text area.east)$);
\coordinate (E) at  ($(B-|current page text area.east)$);
\coordinate (F) at  ($(B-|current page text area.west)$);
\coordinate (G) at  ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at  ($(C)+(0.5\tw,0)$);
\coordinate (I) at  ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at  ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at  ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at  ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at  ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at  ($(E)+(-0.5\tw,0)$);
\coordinate (O) at  ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at  ($(F)+(0.4\tw,-0.5\bs)$);

\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);

\end{tikzpicture}
\newenvironment{mynote}{\tikzmark{AA}}{\tikzmark{BB}}
\begin{mynote}
I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ.
\end{mynote}
\par
This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it.
\par
\begin{mynote}
	I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. 
\end{mynote}
\end{document}

چگونه می توان این مشکل را حل کرد؟

توجه! ممکن است برای دیدن خروجی کامل نیاز به چند بار پردازش باشد.

2 پاسخ

+3 رای

سلام
همان‌گونه که جناب خلیقی گفتند این مشکل به خاطر قرار دادن مختصات در هر مرحله از استفاده‌ی این محیط است.


من برای رفع این مشکل محیط شما را با تعریف زیر تغییر داده‌ام:

\newenvironment{mynote}[1]{\begin{figure}[H]\tikzmark{AA}\spirit{#1}}{\tikzmark{BB}\end{figure}}

این محیط یک آرگومان دارد که به متن درون آن بستگی دارد. (البته به کمک جعبه‌ها می‌توانید روی این ماکرو کار کنید تا این ارتفاع به صورت خودکار درج گردد).
از دو ساختار زیر از بسته‌ی etoolbox نیز برای تنظیم فاصله‌ی قبل و بعد از محیط mynote بهره گرفته‌ام:

\BeforeBeginEnvironment{mynote}{\vspace*{.5cm}}
\AfterEndEnvironment{mynote}{\vspace*{.4cm}}

با این توضیحات دستورات شما مطابق زیر است:


\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\usepackage{float}
\usepackage{etoolbox}
\BeforeBeginEnvironment{mynote}{\vspace*{.5cm}}
\AfterEndEnvironment{mynote}{\vspace*{.4cm}}
\newenvironment{mynote}[1]{\begin{figure}[H]\tikzmark{AA}\spirit{#1}}{\tikzmark{BB}\end{figure}}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\newcommand{\spirit}[1]{
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A)  at(0,.7)($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at(0,#1) ($(pic cs:BB)+(0,-1\bs)$); 
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at  ($(A-|current page text area.east)$);
\coordinate (E) at  ($(B-|current page text area.east)$);
\coordinate (F) at  ($(B-|current page text area.west)$);
\coordinate (G) at  ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at  ($(C)+(0.5\tw,0)$);
\coordinate (I) at  ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at  ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at  ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at  ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at  ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at  ($(E)+(-0.5\tw,0)$);
\coordinate (O) at  ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at  ($(F)+(0.4\tw,-0.5\bs)$);
\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);
\end{tikzpicture}
}
This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it.
%\begin{figure}[H]
\begin{mynote}{-2.4}
I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ.
\end{mynote}
%\end{figure}
This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it.
\begin{mynote}{-1.7}
I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. 
\end{mynote}
\begin{mynote}{-1.7}
I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. 
\end{mynote}
\end{document}

خروجی شما با نسخه‌ی اولیه از تکلایو 2018 مطابق زیر است:


enter image description here


موفق باشید.

موفق باشد.

بسیار عالی +1
توسط (596 امتیاز)
بسیار ممنون. مشکل تداخل حل میشه. برای اجتناب از تنظیم دستی ارتفاع محیط چه راه حلی پیشنهاد می کنید؟
توسط (735 امتیاز)
M J Rezaeiani@
به علت اینکه محدودیت کاراکتر برای ایجاد این ویرایش در پاسخ قبلی داشتم مجبور شدم به عنوان پاسخ جدید این ویرایش را قرار دهم و از این بابت از تمام دوستان عذرخواهی می‌کنم.
پاسخ جدید را ببینید.
توسط (8.7k امتیاز)
@باغبان  سپاسگزارم
توسط (8.7k امتیاز)
استفاده از محیط شناوری چون figure یک سواستفاده است. گذشته از این احتیاجی به استفاده از بسته etoolbox و دو دستور \BeforeBeginEnvironment و \AfterEndEnvironment نیست. بنابراین این پاسخ اشتباه است. همانطور که در پاسخم اشاره کردم پرسش‌کننده از ابزاری اشتباه برای کارش استفاده می‌کند. remember picture و overlay تنها مناسب این است که یک بار در صفحه استفاده شود نه چندین بار.
توسط (26.4k امتیاز)
+2 رای

توجه: این پاسخ یک پاسخ جدید نیست

به علت اینکه محدودیت کاراکتر برای ایجاد این ویرایش در پاسخ قبلی داشتم مجبور شدم به عنوان پاسخ جدید این ویرایش را قرار دهم و از این بابت از تمام دوستان عذرخواهی می‌کنم.

ویرایش دوم بنا به درخواست شما در قسمت نظرات


همان‌طور که در بالا خدمتتان توضیح دادم به کمک جعبه‌ها می‌توان این‌کار را انجام داد و محیط را طوری تعریف کرد که متناسب با محتوایش تغییر ارتفاع دهد.
برای این‌کار ابتدا ماکروی زیر را جهت ذخیره‌ی بلندای محتوا (کمی بیشتر) تعریف کرده‌ام:

\newcommand{\madadpour}{\the\dimexpr-\ht\madadbox-\dp\madadbox-5pt}

تعریف محیط را نیز به ساختار زیر تغییر داده‌ام:

\newenvironment{mynote}[1]{\begin{figure}[H]\tikzmark{AA}\spirit{\madadpour}}{\tikzmark{BB}\end{figure}}

سپس به کمک ساختار زیر به استقبال محیط مورد نظر شما با نام love رفته‌ام:

\newsavebox{\madadbox}
\newenvironment{love}
{\begin{lrbox}{\madadbox}\begin{minipage}[t]{.95\textwidth}\noindent}
		{\end{minipage}\end{lrbox}
	\begin{mynote}
		\vbox{\usebox{\madadbox}}
	\end{mynote}
}

پس دستورات شما در کل مطابق زیر است:


\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\usepackage{float}
\usepackage{etoolbox}
\BeforeBeginEnvironment{mynote}{\vspace*{.5cm}}
\AfterEndEnvironment{mynote}{\vspace*{.4cm}}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\newcommand{\spirit}[1]{
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A)  at(0,.7)($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at(0,#1) ($(pic cs:BB)+(0,-1\bs)$); 
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at  ($(A-|current page text area.east)$);
\coordinate (E) at  ($(B-|current page text area.east)$);
\coordinate (F) at  ($(B-|current page text area.west)$);
\coordinate (G) at  ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at  ($(C)+(0.5\tw,0)$);
\coordinate (I) at  ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at  ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at  ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at  ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at  ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at  ($(E)+(-0.5\tw,0)$);
\coordinate (O) at  ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at  ($(F)+(0.4\tw,-0.5\bs)$);
\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);
\end{tikzpicture}
}
\newcommand{\madadpour}{\the\dimexpr-\ht\madadbox-\dp\madadbox-5pt}
\newenvironment{mynote}[1]{\begin{figure}[H]\tikzmark{AA}\spirit{\madadpour}}{\tikzmark{BB}\end{figure}}
\newsavebox{\madadbox}
\newenvironment{love}
{\begin{lrbox}{\madadbox}\begin{minipage}[t]{.95\textwidth}\noindent}
{\end{minipage}\end{lrbox}
\begin{mynote}
\vbox{\usebox{\madadbox}}
\end{mynote}
}
Does this work in an environment form?  I would love if it did
\begin{love}
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did

Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
\end{love}
\begin{love}
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
\end{love}
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I would love if it did
\begin{love}
Does this work in an environment form?  I would love if it did
Does this work in an environment form?  I 
\end{love}
\begin{love}
Does this work in an environment form?  I would love if it did\\
\begin{center}
{\Huge{\color{magenta} Madadpour}}
\end{center}
\end{love}
\end{document}

خروجی شما با نسخه‌ی اولیه‌ی تکلایو 2018 مطابق زیر است:


enter image description here


محیط شما قابلیت شکستن بین صفحات رو نداره. همچنین اندازه‌گیری شما مشکل داره و منطقی نیست.
توسط (26.4k امتیاز)
درود فراوان.
توسط (735 امتیاز)
پرسیدن سوال
سایت پرسش و پاسخ پارسی‌لاتک جایی برای پرسش و پاسخ درباره سیستم حروف‌چینی لاتک و بسته زی‌پرشین است. در اینجا می‌توانید سوال‌های خود را بپرسید و به سوال‌های دیگران پاسخ دهید.

7.2k پرسش

6.6k پاسخ

23.7k نظر

11.7k کاربر

basket cart icon

محصولات مرتبط با LaTeX

در فروشگاه پارسی‌لاتک


basket cart icon

حمایت مالی از پارسی‌لاتک

برای تامین هزینه‌های نگه‌داری و به‌روزرسانی

محبوب‌ترین برچسب‌ها

رفع خطا جدول xepersian مراجع ریاضی‌نویسی bidi شکل فونت فهرست مطالب شماره‌گذاری منابع پانویس tikz parsilatex بیب‌تک تک‌لایو بیمر اسلاید زی‌پرشین پاورقی سربرگ bibtex نماد رسم شکل فرمول‌نویسی هدر ارجاع‌دهی biditexmaker ویرایشگر قالب beamer واژه‌نامه texstudio اندازه فونت عنوان فصل ماتریس شماره صفحه اعمال نشدن تغییرات در پی‌دی‌اف رسم جدول bidipresentation حاشیه رنگ عنوان شکل اسلاید فارسی محیط قضیه گراف حروف‌چینی کد مکان شکل شماره فصل enumerate tabriz_thesis tikzpicture نمایه align زیرنویس شکل کادر itemize الگوریتم فهرست اشکال listings عدم اجرا نیم‌فاصله فاصله بین خطوط متن لاتین و فارسی hyperref بسته قالب پایان‌نامه فرمول نصب تک‌لایو فارسی‌تک نمودار شماره فرمول glossaries کپشن حروف‌چینی چندستونی خروجی فونت فارسی و انگلیسی ماکرونویسی extrafootnotefeatures لاتک biditools شماره پاورقی پیوست‌ سوال امتحانی فاصله‌گذاری فرمول چندضابطه‌ای tex subfigure biditufte-book header texmaker pdf خطا longtable تصویر شمارنده زیرنویس texlive2015 دیاگرام میک‌تک رسم نمودار شماره‌گذاری صفحات پایان نامه فهرست جداول تورفتگی texlive2016 شعر بولد آکولاد kashida میکروسافت ورد تنظیم جدول سوال چهارگزینه‌ای قاب texworks caption اندیس فاصله عمودی lollipop چپ‌چینی iust-thesis multicol فصل‌نویسی tcolorbox اعداد فارسی pgfplots xindy اوبونتو geometry xelatex texlive کاما fancyhdr وسط‌چینی تک لایو 2015 شماره گذاری به‌روزرسانی بسته aimc46 شکست خط صفر توخالی فرمول طولانی قالب کتاب فونت اعداد بیرون‌زدگی bidipoem عنوان بخش پوستر فاصله سطرها نوشتافت tex-programming قرآن tabriz-thesis ایتالیک winedt جستجوی معکوس فلش جایابی تصویر فهرست تصاویر پاراگراف‌بندی بازیابی اطلاعات هایپرلینک فهرست نمادها شمارنده فصل حروف‌چینی شعر font محیط ریاضی minipage رسم کادر جداکننده جدول طولانی به‌روزرسانی شماره‌گذاری فرمول algorithm2e proof equation eps جدول افقی tabular عکس متن فارسی و انگلیسی پانویس چندستونی کمک مالی فاصله خطوط فونت بولد زیرشکل پانویس پاراگرافی ltrfootnote پیوست computeautoilg فرمول چندخطی persian-bib neveshtuft غلط‌گیری املایی فونت ریاضی پیکان لاتکس قلم baselineskip شماره قسمت عنوان جدول
...