اولین بار است که به اینجا می‌آیید؟ راهنمای سایت را بخوانید!
Close Sidebar
وب‌سایت پرسش و پاسخ پارسی‌لاتک جایی برای پرسش و پاسخ درباره سیستم حروف‌چینی لاتک و بسته زی‌پرشین است. در اینجا می‌توانید سوال‌های خود را بپرسید و به سوال‌های دیگران پاسخ دهید.

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

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

تعریف یک محیط قابل استفاده مجدد با استفاده از TikZ

+2 رای
1,457 بازدید

سلام. با استفاده از 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}

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

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

سوال شده تیر 5, 1397 توسط rezaeian (735 امتیاز)
نمایش از نو تیر 7, 1397 توسط وفا

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


موفق باشید.

موفق باشد.

پاسخ داده شده تیر 5, 1397 توسط شاپور مددپور (8,647 امتیاز)
ویرایش شده تیر 6, 1397 توسط شاپور مددپور
بسیار عالی +1
بسیار ممنون. مشکل تداخل حل میشه. برای اجتناب از تنظیم دستی ارتفاع محیط چه راه حلی پیشنهاد می کنید؟
M J Rezaeiani@
به علت اینکه محدودیت کاراکتر برای ایجاد این ویرایش در پاسخ قبلی داشتم مجبور شدم به عنوان پاسخ جدید این ویرایش را قرار دهم و از این بابت از تمام دوستان عذرخواهی می‌کنم.
پاسخ جدید را ببینید.
@باغبان  سپاسگزارم
استفاده از محیط شناوری چون figure یک سواستفاده است. گذشته از این احتیاجی به استفاده از بسته etoolbox و دو دستور \BeforeBeginEnvironment و \AfterEndEnvironment نیست. بنابراین این پاسخ اشتباه است. همانطور که در پاسخم اشاره کردم پرسش‌کننده از ابزاری اشتباه برای کارش استفاده می‌کند. remember picture و overlay تنها مناسب این است که یک بار در صفحه استفاده شود نه چندین بار.
+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


پاسخ داده شده تیر 6, 1397 توسط شاپور مددپور (8,647 امتیاز)
محیط شما قابلیت شکستن بین صفحات رو نداره. همچنین اندازه‌گیری شما مشکل داره و منطقی نیست.
درود فراوان.
...