
아직 게시물에 댓글을 달 수 없어서 이런 질문을 드려야겠습니다. 다음은 예제 링크입니다. (markellos의 마지막 답변은 제가 사용하고 언급한 것입니다.)
하위 파일 Latex가 있는 다른 디렉토리의 그림 경로
그의 경우:
Main.tex:
\providecommand{\main}{.}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
%here is the path
\graphicspath{{\main/images/}{images/}}
\usepackage{subfiles}
\usepackage{blindtext}
\begin{document}
\subfile{\main/chap1/chap1}
\end{document}
chap1.tex
\providecommand{\main}{..}
\documentclass[\main/main.tex]{subfiles}
\begin{document}
\begin{figure}[bh]
\centering
\includegraphics[width=4cm]{f1}
\label{fig:img1}
\caption{ShareLaTeX learn logo}
\end{figure}
Hello, here is some text...
\end{document}
따라서 내 기본 이미지 디렉토리가 'images'라고 가정하고 다음을 사용하여 이를 호출합니다. \includegraphics[width=4cm]{./f1}
(적어도 저는 그렇습니다)
하지만 'images' 내에 'ABC'라는 하위 폴더도 있습니다. \includegraphics를 사용하여 해당 폴더에서 어떻게 호출하나요?
나는 라텍스에 능숙하지 않으며 주로 답변과 다른 템플릿에서 내용을 복사하여 내 취향에 맞게 혼합합니다. 저는 논문을 쓰고 있으며 이미지가 포함된 다른 하위 폴더가 여러 개 있을 것입니다(조직학을 하고 있습니다). 따라서 기본 '이미지' 폴더와 다른 폴더에 분류하는 것이 매우 편리할 것입니다.
시도했지만 \includegraphics{../f1)
하위 폴더를 포함하려면 main.tex에서 이 줄을 수정해야 한다는 메시지가 표시됩니다.
\graphicspath{{\main/images/}{images/}}
하지만 어떻게?
브르
답변1
가족 비유를 용서하십시오. 하지만 친척이 어떻게 구성되어 있고 어떻게 참조되는지 이해하는 데 도움이 될 수 있습니다.
따라서 당신은 Thomas라고 부를 수 있는 폴더이고 부모는 blindhardt라고 부를 수 있습니다. 시스템에 /blindhardt/thomas로 배치되지만 자체 참조를 위해 별칭을 사용할 수 있습니다."."
/blindhardt/thomas/janet 및 /blindhardt/thomas/john 자녀가 있습니다. 자녀의 자신과의 관계를 나타내기 위해
머리말 및 chap1과 같은 별명이 있을 수 있습니다 . 아버지를 나타낼 때는 ./preface 또는 ./chap1이라고 말할 수 있습니다. 그리고 형제자매의 경우 ../더 나이가 많거나 ../더 젊을 수 있습니다. 이제 귀하의 가계도는 다음과 같을 수 있습니다.
/blindhardt/older
/thomas/
/thomas/preface
/thomas/chap1
/younger
좋아, 그게 이제 답변에 대한 상대 경로에 대한 기본 이론입니다.
(가족 성경의) 관리인인 Thomas의 한 부분은 main.tex로 알려져 있습니다.
마켈로스는 깔끔한 모습을 보여줍니다당신의 그 부분(main.tex)이 다음과 같이 식별된다면
\providecommand{\main}{.}
그러면 모든 ../child/story.tex가 귀하를 제공자로 참조할 수 있습니다.
\providecommand{\main}{..} i.e their own parent
또한 그들의 추가 진술
\documentclass[\main/main.tex]{subfiles}
자신과 동일한 하위 그룹(클래스)에 속해 있음을 확인합니다.
가족으로서 귀하는 모든 사진 자산을
/blindhart/somewhere/vault에 보관하는 데 동의하지만 관리인으로서는 이를 부르고 싶습니다.
/blindhart/thomas/images
% 여기에 ./images 및 차세대 {\main\images/}에 대한 저장소 경로가 있습니다.
\graphicspath{{images/}{\main/images/}}
지금까지는 새로운 것이 없습니다. 해당 저장소에 폴더(ABC)를 보관한다고 가정하면
이제 귀하와 귀하의 자녀 모두 교차 색인이 필요합니다.
\graphicspath{{images/}{\main/images/}{images/ABC/}{\main/images/ABC/}}
이제 pic1.png 또는 fig1.pdf가 main/images 또는 /images/ABC에 있는지는 중요하지 않습니다.
모든 직계 파일 계열에서 이를 찾을 수 있습니다.
\includegraphics[width=4cm]{pic1}
Main.tex(한 줄만 변경됨)
\providecommand{\main}{.}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
%here is the NEW path
\graphicspath{{images/}{\main/images/}{images/ABC/}{\main/images/ABC/}}
\usepackage{subfiles}
\usepackage{blindtext}
\begin{document}
\subfile{\main/chap1/chap1}
\end{document}
chap1.tex(더 폭넓은 수용을 제외하고 변경 없음)
\providecommand{\main}{..}
\documentclass[\main/main.tex]{subfiles}
\begin{document}
\begin{figure}[bh]
\centering
% f1 can be any accepted image (png pdf etc.) beware if there are two in different locations then the order WILL become important.
% it can be in ./f1.png it may be in ../images/f1.pdf or even ../images/ABC/f1.eps
\includegraphics[width=4cm]{f1}
\label{fig:img1}
\caption{ShareLaTeX learn logo}
\end{figure}
Hello, here is some text...
\end{document}
분명히 /older와 해당 /children은 동일한 패턴을 따를 수 있지만 모두 /blindhardt/images의 가문에 액세스하려는 경우 중첩된 상대 레이어를 더 많이 추가하기 시작하면 이러한 마스터 이미지에 대한 절대 주소를 포함하는 것이 더 쉬울 수 있습니다. 따라서 당신과 당신의 형제 자매는 추가 할 수 있습니다
\graphicspath{{c:\familydocs\blindhardt\images/}{images/}{\main/images/}{images/ABC/}{\main/images/ABC/}}
위에 공백을 포함하는 방법이 있지만 완전한 호환성을 위해 공백을 포함하지 않는 것이 좋습니다.
위의 모든 내용은 질문의 표현을 기반으로 하지만 모든 tex 파일은 자체적으로 공공 도서관을 방문할 수 있습니다.
기본 라이브러리가 있습니다.${TEXMFHOME}/tex/generic/images
TEXINPUTS=".:.//:c:\road\to\nowhere: "
또한 각 프로젝트를 실행하기 전에 무엇을 하고 있는지 다르게 재정의할 수 있는 변수를 통해 일련의 프로젝트 집단을 지정할 수도 있습니다 .
모든 하위 디렉터리를 의미하는 특수 토큰 .//에 유의하세요.
답변2
tex.SE에 오신 것을 환영합니다.
더 큰 프로젝트를 위해 얼마 전에 도움이 될 만한 내용을 코딩했습니다.
기본 아이디어는 시작과 끝 부분에 후크를 추가하고 \input
그래픽 \include
경로를 자동으로 조정하는 것입니다. \subfile
사용하기 때문에 \input
잘 작동해야합니다.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{blindtext}
% use parent management with current source file
\usepackage{subfiles}
\usepackage{filehook}
\usepackage[parent]{currfile}
\makeatletter
% Define a new stack by letting it to \@empty
\newcommand\newStack[1]{\global\let#1\@empty}
% add element to stack (top): \addStack{<stack>}{<element>}
\newcommand{\addStack}[2]{\def\ele@ment{{#2} }\xdef#1{\ele@ment #1}}
% add element to stack (bottom) \revaddStack{<stack>}{<element>}
\newcommand{\revaddStack}[2]{\def\ele@ment{{#2} }\xdef#1{#1 \ele@ment}}
% remove from stack
\long\def\pop@#1 #2\@nil#3{\def\popedStackElement{#1}%
\def#3{#2}}% remaining list
% stack name #1
\newcommand\popStack[1]{\let\popedStackElement\@empty%
\ifx #1\@empty\message{LaTeX warning: you are trying to remove an element from the empty stack \noexpand#1 on input line \the\inputlineno}\else\expandafter\pop@#1\@nil#1\fi}
% whipe stack
\newcommand\cleanStack[1]{\global\let#1\@empty}
%%% enhanced graphicspath management
% idea: everytime \includegraphics is called from a file of a (larger) project the graphics file is searched
% in a specific folder relative to that one the actual tex source code resides in.
% In addition generally valid paths can be defined.
% idea taken from https://tex.stackexchange.com/questions/45946/stack-datastructure-using-latex ;
% uservariant and autovariant of graphicspath stack
\newStack{\GrapPa@user}
\newStack{\GrapPa@auto}
% activate stack as graphicspath
% def hook for entering file: add path and update graphicspath
\newcommand{\grappa@start@hook}{%
\ifcurrfiledir\@empty{}{\addStack{\GrapPa@auto}{\currfiledir\graphicsfolder}}\update@grappa}
% def hook for leaving file: remove path and update graphicspath
\newcommand{\grappa@end@hook}{%
\ifcurrfiledir\@empty{}{\popStack{\GrapPa@auto}}\update@grappa}
% activate stack as graphicspath
\newcommand{\update@grappa}{\xdef\GrapPa@temp{{\GrapPa@user \GrapPa@auto}}\expandafter\graphicspath\GrapPa@temp}
%
% user space graphicspath stack:
\newcommand{\newaddgraphicspath}[1]{\addStack{\GrapPa@user}{#1}\update@grappa}
\newcommand{\removelastgraphicspath}{\popStack{\GrapPa@user}\update@grappa}
\newcommand{\showgraphicspath}{\message{user: \show\GrapPa@user\space - auto: \show\GrapPa@auto}}
% define default graphics folder name
\newcommand{\graphicsfolder}{images/}
% now register for linking to filehook
\AtBeginDocument{%
\AtBeginOfInputs{\grappa@start@hook}%
\AtBeginOfIncludes{\grappa@start@hook}%
\AtEndOfInputs{\grappa@end@hook}%
\AtEndOfIncludes{\grappa@end@hook}}
%%% enhanced graphicspath management
\makeatother
\newaddgraphicspath{./\graphicsfolder}
\begin{document}
\subfile{./chap1/chap1}
\end{document}
이를 통해 \input
s 및 s를 중첩할 수 있으며 그래픽 파일은 tex 파일이 있는 디렉토리와 관련하여 \include
지정된 폴더에 로드됩니다 .\graphicsfolder
추가 전역 경로가 있는 경우 를 호출하여 추가할 수 있습니다 \newaddgraphicspath
. 그러나 사용은 \removelastgraphicspath
까다로우므로 자신이 무엇을 하고 있는지 알지 않는 한 사용을 피해야 합니다.
호출하면 \showgraphicspath
로그 파일과 콘솔에서 검색된 실제 경로 목록이 제공됩니다.
비교이 훌륭하고 간단한 대답이 솔루션에는 동일한 레벨에서 이미지가 발견되지 않으면 상위 레벨의 모든 레벨도 검색되는 기능이 있습니다. 따라서 첫 번째 레벨 내의 이미지 폴더에 이미지를 넣으면 이 분기의 모든 후속 레벨에 액세스할 수 있습니다. 예를 들어 이를 사용하면 깊게 중첩된 이미지 파일을 복사하거나 매크로를 변경할 필요 없이 다양한 부분과 레벨에 다양한 마커를 추가할 수 있습니다.